web-atoms-core
Version:
71 lines • 2.19 kB
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var AtomDispatcher = /** @class */ (function () {
function AtomDispatcher() {
this.head = null;
this.tail = null;
}
AtomDispatcher.prototype.onTimeout = function () {
var _this = this;
if (this.paused) {
return;
}
if (!this.head) {
return;
}
var item = this.head;
this.head = item.next;
item.next = null;
if (!this.head) {
this.tail = null;
}
item();
setTimeout(function () {
_this.onTimeout();
}, 1);
};
AtomDispatcher.prototype.pause = function () {
this.paused = true;
};
AtomDispatcher.prototype.start = function () {
var _this = this;
this.paused = false;
setTimeout(function () {
_this.onTimeout();
}, 1);
};
AtomDispatcher.prototype.callLater = function (f) {
if (this.tail) {
this.tail.next = f;
this.tail = f;
}
else {
this.head = f;
this.tail = f;
}
if (!this.paused) {
this.start();
}
};
AtomDispatcher.prototype.waitForAll = function () {
var _this = this;
return new Promise(function (resolve, reject) {
_this.callLater(function () {
resolve();
});
});
};
return AtomDispatcher;
}());
exports.AtomDispatcher = AtomDispatcher;
});
//# sourceMappingURL=AtomDispatcher.js.map