You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
runtoolkit edited this page Apr 13, 2026
·
1 revision
Queue
FIFO function queue with a configurable drain rate per flush.
Constructor
import{Queue}from'./src/queue.js';constq=newQueue({rate: 1});// default: 1 item per flush
rate must be a positive integer. Throws RangeError otherwise.
Adding items
q.push(fn);// add a functionq.pushMany([fn1,fn2]);// add multipleq.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.
Flushing
q.flush();// calls up to `rate` items, returns count processedq.flushAll();// calls every item regardless of rate, returns count
When Engine is used, queue.flush() is called automatically every tick via the _queue channel.
Introspection
q.size();// number of queued itemsq.clear();// discard all without running
Changing rate
q.setRate(5);// process up to 5 items per flush
Error handling
Errors thrown inside queued functions are caught and logged to console.error. The queue continues processing remaining items.