Provides a set of static methods for creating Disposables, which defines a method to release allocated resources.
The follow example shows the basic usage of an Disposable
.
const disposable = Disposable.create(() => console.log('disposed'));
disposable.dispose();
// => disposed
Creates a disposable object that invokes the specified action when disposed.
action
Function
: Function to run during the first call todispose
. The action is guaranteed to be run at most once.
Disposable
: The disposable object that runs the given action upon disposal.
const disposable = Disposable.create(() => console.log('disposed'));
disposable.dispose();
// => disposed
Creates a disposable object that invokes the specified action when disposed.
d
:Object
- Object to validate whether it has a dispose method.
Boolean
- true
if is a disposable object, else false
.
const disposable = Disposable.empty;
console.log(Disposable.isDisposable(disposable));
// => true
Gets the disposable that does nothing when disposed.
Disposable
: The disposable that does nothing when disposed.
const disposable = Disposable.empty;
disposable.dispose(); // Does nothing
Performs the task of cleaning up resources.
const disposable = Disposable.create(() => console.log('disposed'));
disposable.dispose();
// => disposed