2.1.3 • Published 7 years ago
using-disposable v2.1.3
using-disposable
what is this?
A C# inspired helper function to allow for automatic disposing of objects.
how does it work
If a class implements the Disposable
interface, it will expose the (async)
function dispose
. An instance of this class cacn be passed to the using
helper function so that the dispose
method is automatically executed.
huh?
Ok, let me show you:
Without using:
const i = await DisposableClass.create();
try {
// do stuff...
}
finally {
await i.dispose();
}
With using (does exactly the same)
await using(DisposableClass.create(), async i => {
// do stuff...
});
This is great for usage in test (cool) test-frameworks like tape with blue-tape.
exaple:
test(
"test something",
t => using(testContext.create(), async testContext => {
const something = await testContext.createSomething();
t.ok(something);
}),
)
2.1.3
7 years ago
2.1.2
7 years ago
2.1.1
7 years ago
2.1.0
7 years ago
2.0.0
7 years ago
1.7.9
7 years ago
1.7.8
7 years ago
1.7.6
7 years ago
1.7.5
7 years ago
1.7.3
7 years ago
1.7.2
7 years ago
1.7.1
7 years ago
1.7.0
7 years ago
1.6.0
7 years ago
1.5.0
7 years ago
1.4.0
7 years ago
1.3.1
7 years ago
1.0.3
8 years ago
1.0.2
8 years ago
1.0.1
8 years ago