New:Socket for Asana Is Now Available.Learn more
Get Started

using-safe

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

using-safe

Safely use and dispose resources, even without the `using` declaration

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
8
14.29%
Maintainers
1
Weekly downloads
 
Created
Source

using-safe

Safely use and dispose resources, even without the using declaration

Install

npm install using-safe

Usage

import usingSafe from 'using-safe';

const result = await usingSafe(resource, async (r) => {
	return await r.doWork();
});
// Resource is automatically disposed

API

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_.

  • disposable-from - Create Disposable wrappers for timers, event listeners, intervals, and custom cleanup

License

MIT

Keywords

using

FAQs

Package last updated on 16 Feb 2026

Related posts