@jbrowse/core
Version:
JBrowse 2 core libraries used by plugins
29 lines (28 loc) • 866 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
class PhasedScheduler {
constructor(...phaseOrder) {
this.phaseCallbacks = new Map();
this.phaseOrder = [];
this.phaseOrder = phaseOrder;
}
add(phase, callback) {
if (!this.phaseOrder.includes(phase)) {
throw new Error(`unknown phase ${phase}`);
}
let phaseCallbacks = this.phaseCallbacks.get(phase);
if (!phaseCallbacks) {
phaseCallbacks = [];
this.phaseCallbacks.set(phase, phaseCallbacks);
}
phaseCallbacks.push(callback);
}
run() {
for (const phaseName of this.phaseOrder) {
for (const callback of this.phaseCallbacks.get(phaseName) || []) {
callback();
}
}
}
}
exports.default = PhasedScheduler;
;