using-safe
v1.0.0
Published
Safely use and dispose resources, even without the `using` declaration
Downloads
88
Maintainers
Readme
using-safe
Safely use and dispose resources, even without the
usingdeclaration
Install
npm install using-safeUsage
import usingSafe from 'using-safe';
const result = await usingSafe(resource, async (r) => {
return await r.doWork();
});
// Resource is automatically disposedAPI
usingSafe(resource, function_)
Runs function_ with resource, then disposes resource in a finally block.
Disposal order: Symbol.asyncDispose -> Symbol.dispose -> .close() -> .destroy()
Returns the result of function_.
usingSafeSync(resource, function_)
Synchronous version.
Disposal order: Symbol.dispose -> .close() -> .destroy()
Returns the result of function_.
Related
- disposable-from - Create Disposable wrappers for timers, event listeners, intervals, and custom cleanup
License
MIT
