@ocap/util
Version:
utils shared across multiple forge js libs, works in both node.js and browser
35 lines (33 loc) • 848 B
JavaScript
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
let node_events = require("node:events");
node_events = require_rolldown_runtime.__toESM(node_events);
//#region src/ready.ts
var Ready = class extends node_events.default {
constructor() {
super();
this.ready = false;
this.readyCallbacks = [];
this.readyMarks = {};
}
markReady(mark) {
if (this.ready) return;
if (mark === void 0) {
this.ready = true;
this.readyCallbacks.forEach((x) => x());
this.emit("ready");
} else {
this.readyMarks[mark] = true;
this.ready = Object.values(this.readyMarks).every((x) => !!x);
if (this.ready) {
this.readyCallbacks.forEach((cb) => cb());
this.emit("ready");
}
}
}
onReady(cb) {
if (this.ready) cb();
else this.readyCallbacks.push(cb);
}
};
//#endregion
exports.Ready = Ready;