windowmanager
Version:
A framework to manage multiple dockable, HTML windows
24 lines (18 loc) • 548 B
JavaScript
function SyncCallback(callback) {
if (!(this instanceof SyncCallback)) { return new SyncCallback(callback); }
this.callback = callback;
this.count = 0;
}
SyncCallback.prototype.ref = function (callback) {
let thisRef = this;
this.count += 1;
return function (...args) {
if (callback) { callback(...args); }
thisRef._deref();
};
};
SyncCallback.prototype._deref = function () {
this.count -= 1;
if (this.count <= 0) { this.callback(); }
};
export default SyncCallback;