@zkochan/pnpm
Version:
Fast, disk space efficient package manager
41 lines (31 loc) • 870 B
JavaScript
/** @license MIT License (c) copyright 2010-2016 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
export default 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
}