Disposable class

Represents a type which can release resources, such as event listening or a timer.

Constructors

Disposable(() => any)

Creates a new disposable that calls the provided function on dispose. Note that an asynchronous function is not awaited.

Methods

dispose()

Dispose this object.

from({ dispose: () => any }[])

Combine many disposable-likes into one. You can use this method when having objects with a dispose function which aren't instances of Disposable.

Constructor Details

Disposable(() => any)

Creates a new disposable that calls the provided function on dispose. Note that an asynchronous function is not awaited.

new Disposable(callOnDispose: () => any)

Parameters

callOnDispose

() => any

Function that disposes something.

Method Details

dispose()

Dispose this object.

function dispose(): any

Returns

any

from({ dispose: () => any }[])

Combine many disposable-likes into one. You can use this method when having objects with a dispose function which aren't instances of Disposable.

static function from(disposableLikes: { dispose: () => any }[]): Disposable

Parameters

disposableLikes

{ dispose: () => any }[]

Objects that have at least a dispose-function member. Note that asynchronous dispose-functions aren't awaited.

Returns

Returns a new disposable which, upon dispose, will dispose all provided disposables.