This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

dispose
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

dispose

CircleCI

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);
    }),
)

/dispose/

    Package Sidebar

    Install

    npm i dispose

    Weekly Downloads

    2

    Version

    1.0.3

    License

    ISC

    Unpacked Size

    18.1 kB

    Total Files

    35

    Last publish

    Collaborators

    • elmerbulthuis