-
Notifications
You must be signed in to change notification settings - Fork 1
Queue
runtoolkit edited this page Apr 13, 2026
·
1 revision
FIFO function queue with a configurable drain rate per flush.
import { Queue } from './src/queue.js';
const q = new Queue({ rate: 1 }); // default: 1 item per flushrate must be a positive integer. Throws RangeError otherwise.
q.push(fn); // add a function
q.pushMany([fn1, fn2]); // add multiple
q.pushAs(fn, ctx); // wraps fn so it receives ctx when called
// equivalent to: q.push(() => fn(ctx))Only functions are accepted. Throws TypeError for other types.
q.flush(); // calls up to `rate` items, returns count processed
q.flushAll(); // calls every item regardless of rate, returns countWhen Engine is used, queue.flush() is called automatically every tick via the _queue channel.
q.size(); // number of queued items
q.clear(); // discard all without runningq.setRate(5); // process up to 5 items per flushErrors thrown inside queued functions are caught and logged to console.error. The queue continues processing remaining items.