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

Latest commit

 

History

History
146 lines (89 loc) · 3.03 KB

serialdisposable.md

File metadata and controls

146 lines (89 loc) · 3.03 KB

SerialDisposable class

Represents a disposable resource whose underlying disposable resource can be replaced by another disposable resource, causing automatic disposal of the previous underlying disposable resource.

Usage

The follow example shows the basic usage of a SerialDisposable.

const serialDisposable = new SerialDisposable();

const d1 = Disposable.create(() => console.log('one'));

serialDisposable.setDisposable(d1);

const d2 = Disposable.create(() => console.log('two'));

serialDisposable.setDisposable(d2);
// => one

serialDisposable.dispose();
// = two

SerialDisposable Constructor

SerialDisposable Instance Methods

SerialDisposable Instance Properties

SerialDisposable Constructor

SerialDisposable()

Initializes a new instance of the SerialDisposable class.

Example

const serialDisposable = new SerialDisposable();

console.log(serialDisposable.isDisposed);
// => false

SerialDisposable Instance Methods

SerialDisposable.prototype.dispose()

Disposes the underlying disposable as well as all future replacements.

Example

const serialDisposable = new SerialDisposable();

const d1 = Disposable.create(() => console.log('one'));

serialDisposable.setDisposable(d1);

serialDisposable.dispose();
// => one

SerialDisposable.prototype.getDisposable()

Gets the underlying disposable.

Returns

Disposable - The underlying disposable.

Example

const serialDisposable = new SerialDisposable();

const d1 = Disposable.create(() => console.log('one'));

serialDisposable.setDisposable(d1);

console.log(serialDisposable.getDisposable() === d1);
// => true

SerialDisposable.prototype.setDisposable(value)

Sets the underlying disposable.

Arguments

  1. value Disposable: The new underlying disposable.

Example

const serialDisposable = new SerialDisposable();

const d1 = Disposable.create(() => console.log('one'));

serialDisposable.setDisposable(d1);

serialDisposable.dispose();
// => one

const d2 = Disposable.create(() => console.log('two'));

serialDisposable.setDisposable(d2);
// => two

SerialDisposable Instance Properties

isDisposed

Gets a value that indicates whether the object is disposed.

Example

const serialDisposable = new SerialDisposable();

const d1 = Disposable.create(() => console.log('one'));

serialDisposable.setDisposable(d1);

console.log(serialDisposable.isDisposed);
// => false

serialDisposable.dispose();
// => one

console.log(serialDisposable.isDisposed);
// => true