disposer
v0.1.1
Published
an async disposer and abstract disposable class
Downloads
4
Readme
Disposer
an async disposer and abstract disposable class
Class: Disposable
import { Disposable, using, Disposer } from "disposer";
class Foo extends Disposable {
constructor(){
super();
this.addDisposer(()=>{
console.log("clean up something");
})
}
}
let foo = new Foo();
foo.on("disposing", ()=>console.log("disposing"));
foo.on("disposed", ()=>console.log("disposed"));
async function main(){
await foo.dispose();
}
main().catch(console.log);
Class: Disposer
let foo = new Disposer();
foo.addDisposer(()=>{
console.log("clean up something");
})
Function: using
async function main(){
await using(new Foo(), (foo)=>{
//do something
});
//foo disposed
}