Represents a disposable resource whose underlying disposable resource can be replaced by another disposable resource, causing automatic disposal of the previous underlying disposable resource.
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
Initializes a new instance of the SerialDisposable
class.
const serialDisposable = new SerialDisposable();
console.log(serialDisposable.isDisposed);
// => false
Disposes the underlying disposable as well as all future replacements.
const serialDisposable = new SerialDisposable();
const d1 = Disposable.create(() => console.log('one'));
serialDisposable.setDisposable(d1);
serialDisposable.dispose();
// => one
Gets the underlying disposable.
Disposable
- The underlying disposable.
const serialDisposable = new SerialDisposable();
const d1 = Disposable.create(() => console.log('one'));
serialDisposable.setDisposable(d1);
console.log(serialDisposable.getDisposable() === d1);
// => true
Sets the underlying disposable.
value
Disposable
: The new underlying disposable.
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
Gets a value that indicates whether the object is disposed.
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