81 lines
1.9 KiB
JavaScript
81 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
exports.__esModule = true;
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
|
|
var _isDisposable = require('./isDisposable');
|
|
|
|
var _isDisposable2 = _interopRequireDefault(_isDisposable);
|
|
|
|
var SerialDisposable = (function () {
|
|
function SerialDisposable() {
|
|
_classCallCheck(this, SerialDisposable);
|
|
|
|
this.isDisposed = false;
|
|
this.current = null;
|
|
}
|
|
|
|
/**
|
|
* Gets the underlying disposable.
|
|
* @return The underlying disposable.
|
|
*/
|
|
|
|
SerialDisposable.prototype.getDisposable = function getDisposable() {
|
|
return this.current;
|
|
};
|
|
|
|
/**
|
|
* Sets the underlying disposable.
|
|
* @param {Disposable} value The new underlying disposable.
|
|
*/
|
|
|
|
SerialDisposable.prototype.setDisposable = function setDisposable() {
|
|
var value = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0];
|
|
|
|
if (value != null && !_isDisposable2['default'](value)) {
|
|
throw new Error('Expected either an empty value or a valid disposable');
|
|
}
|
|
|
|
var isDisposed = this.isDisposed;
|
|
var previous = undefined;
|
|
|
|
if (!isDisposed) {
|
|
previous = this.current;
|
|
this.current = value;
|
|
}
|
|
|
|
if (previous) {
|
|
previous.dispose();
|
|
}
|
|
|
|
if (isDisposed && value) {
|
|
value.dispose();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Disposes the underlying disposable as well as all future replacements.
|
|
*/
|
|
|
|
SerialDisposable.prototype.dispose = function dispose() {
|
|
if (this.isDisposed) {
|
|
return;
|
|
}
|
|
|
|
this.isDisposed = true;
|
|
var previous = this.current;
|
|
this.current = null;
|
|
|
|
if (previous) {
|
|
previous.dispose();
|
|
}
|
|
};
|
|
|
|
return SerialDisposable;
|
|
})();
|
|
|
|
exports['default'] = SerialDisposable;
|
|
module.exports = exports['default']; |