Skip to content

Latest commit

 

History

History
192 lines (122 loc) · 4.87 KB

singleassignmentdisposable.md

File metadata and controls

192 lines (122 loc) · 4.87 KB

Rx.SingleAssignmentDisposable class

Represents a disposable resource which only allows a single assignment of its underlying disposable resource. If an underlying disposable resource has already been set, future attempts to set the underlying disposable resource will throw an Error.

Usage

The follow example shows the basic usage of an Rx.SingleAssignmentDisposable.

var singleDisposable = new Rx.SingleAssignmentDisposable();

var disposable = Rx.Disposable.create(function () {
     console.log('disposed');
});

singleDisposable.setDisposable(disposable);

singleDisposable.dispose();
// => disposed

Location

  • rx.js

SingleAssignmentDisposable Constructor

SingleAssignmentDisposable Instance Methods

SingleAssignmentDisposable Instance Properties

SingleAssignmentDisposable Constructor

Rx.SingleAssignmentDisposable()

#

Initializes a new instance of the Rx.SingleAssignmentDisposable class.

Example

var singleDisposable = new Rx.SingleAssignmentDisposable();

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

Location

  • rx.js

SingleAssignmentDisposable Instance Methods

Rx.SingleAssignmentDisposable.prototype.dispose()

#

Disposes the underlying disposable.

Example

var singleDisposable = new Rx.SingleAssignmentDisposable();

var disposable = Rx.Disposable.create(function () {
     console.log('disposed');
});

singleDisposable.setDisposable(disposable);

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

singleDisposable.dispose();
// => disposed

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

Location

  • rx.js

Rx.SingleAssignmentDisposable.prototype.getDisposable()

#

Gets the underlying disposable. After disposal, the result of getting this method is undefined.

Returns

(Disposable): The underlying disposable.

Example

var singleDisposable = new Rx.SingleAssignmentDisposable();

var disposable = Rx.Disposable.create(function () {
     console.log('disposed');
});

singleDisposable.setDisposable(disposable);

var d = singleDisposable.getDisposable();

console.log(d === disposable);

Location

  • rx.js

Rx.SingleAssignmentDisposable.prototype.setDisposable(value)

#

Sets the underlying disposable.

Arguments

  1. value (Disposable): The new underlying disposable.

Example

var singleDisposable = new Rx.SingleAssignmentDisposable();

var d1 = Rx.Disposable.create(function () {
     console.log('one');
});

singleDisposable.setDisposable(d1);

var d2 = Rx.Disposable.create(function () {
     console.log('two');
});

try {
    singleDisposable.setDisposable(d2);
} catch (e) {
    console.log(e.message);
}

// => Disposable has already been assigned

Location

  • rx.js

SingleAssignmentDisposable Instance Properties

isDisposed

#

Gets a value that indicates whether the object is disposed.

Example

var singleDisposable = new Rx.SingleAssignmentDisposable();

var disposable = Rx.Disposable.create(function () {
     console.log('disposed');
});

singleDisposable.setDisposable(disposable);

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

singleDisposable.dispose();
// => disposed

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

Location

  • rx.js