Check if a value implements the Disposable or AsyncDisposable protocol
npm install has-disposableimport hasDisposable, {hasAsyncDisposable} from 'has-disposable';
const resource = {
[Symbol.dispose]() {
console.log('disposed');
},
};
hasDisposable(resource);
//=> true
hasDisposable({});
//=> false
const asyncResource = {
async [Symbol.asyncDispose]() {
console.log('async disposed');
},
};
hasAsyncDisposable(asyncResource);
//=> trueReturns true when value[Symbol.dispose] is a function, including methods
inherited through the prototype chain. Nullish values return false. Primitive
values can return true when their boxed prototype defines the method.
Returns true if the value has a Symbol.dispose method.
Type: unknown
The value to check.
Returns true when value[Symbol.asyncDispose] is a function, including
inherited methods. Nullish values return false. Primitive values can return
true when their boxed prototype defines the method.
Returns true if the value has a Symbol.asyncDispose method.
Type: unknown
The value to check.
- using - TC39 Explicit Resource Management proposal
MIT