Rx.RefCountDisposable class

Represents a disposable resource that only disposes its underlying disposable resource when all getDisposable dependent disposable objects have been disposed.

Usage

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

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

var refCountDisposable = new Rx.RefCountDisposable(disposable);

// Try disposing before the underlying is disposed
refCountDisposable.dispose();

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

// Dispose the underlying disposable
disposable.dispose();
// => disposed

// Now dispose the primary
refCountDisposable.dispose();

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

Location

  • rx.js

RefCountDisposable Constructor

RefCountDisposable Instance Methods

RefCountDisposable Instance Properties

RefCountDisposable Constructor

Rx.RefCountDisposable(disposable)

#

Initializes a new instance of the Rx.RefCountDisposable class with the specified disposable

Arguments

  1. disposable (Disposable): Underlying disposable.

Example

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

var refCountDisposable = new Rx.RefCountDisposable(disposable);

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

Location

  • rx.js

RefCountDisposable Instance Methods

Rx.RefCountDisposable.prototype.dispose()

#

Disposes the underlying disposable only when all dependent disposables have been disposed.

Example

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

var refCountDisposable = new Rx.RefCountDisposable(disposable);

// Try disposing before the underlying is disposed
refCountDisposable.dispose();

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

// Dispose the underlying disposable
disposable.dispose();
// => disposed

// Now dispose the primary
refCountDisposable.dispose();

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

Location

  • rx.js

Rx.RefCountDisposable.prototype.getDisposable()

#

Returns a dependent disposable that when disposed decreases the refcount on the underlying disposable.

Returns

(Disposable): A dependent disposable contributing to the reference count that manages the underlying disposable's lifetime.

Example

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

var refCountDisposable = new Rx.RefCountDisposable(disposable);

var d = refCountDisposable.getDisposable();

console.log(d === disposable);
// => false

// Clean up disposables
disposable.dispose();
d.dispose();

// Now try to dispose the main
refCountDisposable.dispose();

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

Location

  • rx.js

RefCountDisposable Instance Properties

isDisposed

#

Gets a value that indicates whether the object is disposed.

Example

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

var refCountDisposable = new Rx.RefCountDisposable(disposable);

disposable.dispose();

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

refCountDisposable.dispose();
// => disposed

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

Location

  • rx.js