UNPKG

@tldraw/utils

Version:

tldraw infinite canvas SDK (private utilities).

60 lines (59 loc) 1.79 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var ExecutionQueue_exports = {}; __export(ExecutionQueue_exports, { ExecutionQueue: () => ExecutionQueue }); module.exports = __toCommonJS(ExecutionQueue_exports); var import_control = require("./control"); class ExecutionQueue { constructor(timeout) { this.timeout = timeout; } queue = []; running = false; isEmpty() { return this.queue.length === 0 && !this.running; } async run() { if (this.running) return; try { this.running = true; while (this.queue.length) { const task = this.queue.shift(); await task(); if (this.timeout) { await (0, import_control.sleep)(this.timeout); } } } finally { this.running = false; } } async push(task) { return new Promise((resolve, reject) => { this.queue.push(() => Promise.resolve(task()).then(resolve).catch(reject)); this.run(); }); } close() { this.queue = []; } } //# sourceMappingURL=ExecutionQueue.js.map