This repository has been archived on 2023-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
mightyscape-1.1-deprecated/extensions/fablabchemnitz/papercraft/openjscad/node_modules/most/lib/disposable/SettableDisposable.js

46 lines
986 B
JavaScript

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = SettableDisposable;
/** @license MIT License (c) copyright 2010-2016 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
function SettableDisposable() {
this.disposable = void 0;
this.disposed = false;
this._resolve = void 0;
var self = this;
this.result = new Promise(function (resolve) {
self._resolve = resolve;
});
}
SettableDisposable.prototype.setDisposable = function (disposable) {
if (this.disposable !== void 0) {
throw new Error('setDisposable called more than once');
}
this.disposable = disposable;
if (this.disposed) {
this._resolve(disposable.dispose());
}
};
SettableDisposable.prototype.dispose = function () {
if (this.disposed) {
return this.result;
}
this.disposed = true;
if (this.disposable !== void 0) {
this.result = this.disposable.dispose();
}
return this.result;
};