Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Latest commit

 

History

History
100 lines (64 loc) · 2.15 KB

disposable.md

File metadata and controls

100 lines (64 loc) · 2.15 KB

Disposable class

Provides a set of static methods for creating Disposables, which defines a method to release allocated resources.

Usage

The follow example shows the basic usage of an Disposable.

const disposable = Disposable.create(() => console.log('disposed'));

disposable.dispose();
// => disposed

Disposable Class Methods

Disposable Class Properties

Disposable Instance Methods

Class Methods

Disposable.create(action)

Creates a disposable object that invokes the specified action when disposed.

Arguments

  1. action Function: Function to run during the first call to dispose. The action is guaranteed to be run at most once.

Returns

Disposable: The disposable object that runs the given action upon disposal.

Example

const disposable = Disposable.create(() => console.log('disposed'));

disposable.dispose();
// => disposed

Disposable.isDisposable(d)

Creates a disposable object that invokes the specified action when disposed.

Arguments

  1. d: Object - Object to validate whether it has a dispose method.

Returns

Boolean - true if is a disposable object, else false.

Example

const disposable = Disposable.empty;
console.log(Disposable.isDisposable(disposable));
// => true

Disposable Class Properties

Disposable.empty

Gets the disposable that does nothing when disposed.

Returns

Disposable: The disposable that does nothing when disposed.

Example

const disposable = Disposable.empty;

disposable.dispose(); // Does nothing

Disposable Instance Methods

Disposable.prototype.dispose()

Performs the task of cleaning up resources.

Example

const disposable = Disposable.create(() => console.log('disposed'));

disposable.dispose();
// => disposed