UNPKG

@web-atoms/core

Version:
64 lines (63 loc) 1.46 kB
System.register([], function (_export, _context) { "use strict"; var AtomDispatcher; _export("AtomDispatcher", void 0); return { setters: [], execute: function () { _export("AtomDispatcher", AtomDispatcher = class AtomDispatcher { constructor() { this.head = null; this.tail = null; } onTimeout() { if (this.paused) { return; } if (!this.head) { return; } const item = this.head; this.head = item.next; item.next = null; if (!this.head) { this.tail = null; } item(); setTimeout(() => { this.onTimeout(); }, 1); } pause() { this.paused = true; } start() { this.paused = false; setTimeout(() => { this.onTimeout(); }, 1); } callLater(f) { if (this.tail) { this.tail.next = f; this.tail = f; } else { this.head = f; this.tail = f; } if (!this.paused) { this.start(); } } waitForAll() { return new Promise((resolve, reject) => { this.callLater(() => { resolve(); }); }); } }); } }; }); //# sourceMappingURL=AtomDispatcher.js.map