Skip to content

Latest commit

 

History

History
186 lines (121 loc) · 4.47 KB

refcountdisposable.md

File metadata and controls

186 lines (121 loc) · 4.47 KB

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(function () {
     console.log('disposed');
});

var refCountDisposable = new Rx.RefCountDisposable(disposable);

var disposable1 = refCountDisposable.getDisposable();
var disposable2 = refCountDisposable.getDisposable();

disposable1.dispose();
console.log(disposable.isDisposed);
// => false

disposable2.dispose();
console.log(disposable.isDisposed);
// => false

refCountDisposable.dispose();
// => disposed

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(function () {
     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(function () {
     console.log('disposed');
});

var refCountDisposable = new Rx.RefCountDisposable(disposable);

var disposable1 = refCountDisposable.getDisposable();
var disposable2 = refCountDisposable.getDisposable();

disposable1.dispose();
console.log(disposable.isDisposed);
// => false

disposable2.dispose();
console.log(disposable.isDisposed);
// => false

refCountDisposable.dispose();
// => disposed

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(function () {
     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(function () {
     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