Represents a disposable resource that only disposes its underlying disposable resource when all getDisposable
dependent disposable objects have been disposed.
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);
// 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
- rx.js
Initializes a new instance of the Rx.RefCountDisposable
class with the specified disposable
disposable
(Disposable): Underlying disposable.
var disposable = Rx.Disposable.create(function () {
console.log('disposed');
});
var refCountDisposable = new Rx.RefCountDisposable(disposable);
console.log(refCountDisposable.isDisposed);
// => false
- rx.js
Disposes the underlying disposable only when all dependent disposables have been disposed.
var disposable = Rx.Disposable.create(function () {
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
- rx.js
Returns a dependent disposable that when disposed decreases the refcount on the underlying disposable.
(Disposable): A dependent disposable contributing to the reference count that manages the underlying disposable's lifetime.
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
- rx.js
Gets a value that indicates whether the object is disposed.
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
- rx.js