Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 26x 26x 26x 24x 24x 24x 26x 26x 11x 11x 11x 11x 24x 24x 24x 24x 24x 25x 25x 25x 26x 26x 26x 26x 25x 24x 24x 24x 24x | const queue = new Set();
let isPending = false;
let isFlushing = false;
/**
* Queues a job (update callback) to be executed in the next microtask.
* Deduplicates multiple calls to the same job.
* @param {Function} job - The callback to run.
*/
export function queueJob(job) {
if (!queue.has(job)) {
queue.add(job);
if (!isPending && !isFlushing) {
isPending = true;
Promise.resolve().then(flushJobs);
}
}
}
/**
* Flushes all queued jobs in a loop until the queue is completely empty.
*/
function flushJobs() {
isPending = false;
isFlushing = true;
try {
while (queue.size > 0) {
const jobs = Array.from(queue);
queue.clear();
for (const job of jobs) {
try {
job();
} catch (error) {
console.error('Error executing scheduled job:', error);
}
}
}
} finally {
isFlushing = false;
}
}
|