Defined in: queuer.ts:243
A flexible queue that processes items with configurable wait times, expiration, and priority.
Features:
Running behavior:
Manual processing is also supported when automatic processing is disabled:
Queue behavior defaults to FIFO:
Priority queue:
Stack (LIFO):
Double-ended queue:
Item expiration:
State Management:
Example usage:
// Auto-processing queue with wait time
const autoQueue = new Queuer<number>((n) => console.log(n), {
started: true, // Begin processing immediately
wait: 1000, // Wait 1s between items
onExecute: (item) => console.log(`Processed ${item}`)
});
autoQueue.addItem(1); // Will process after 1s
autoQueue.addItem(2); // Will process 1s after first item
// Manual processing queue
const manualQueue = new Queuer<number>((n) => console.log(n), {
started: false
});
manualQueue.addItem(1); // [1]
manualQueue.addItem(2); // [1, 2]
manualQueue.execute(); // logs 1, queue is [2]
manualQueue.getNextItem(); // returns 2, queue is empty
// Auto-processing queue with wait time
const autoQueue = new Queuer<number>((n) => console.log(n), {
started: true, // Begin processing immediately
wait: 1000, // Wait 1s between items
onExecute: (item) => console.log(`Processed ${item}`)
});
autoQueue.addItem(1); // Will process after 1s
autoQueue.addItem(2); // Will process 1s after first item
// Manual processing queue
const manualQueue = new Queuer<number>((n) => console.log(n), {
started: false
});
manualQueue.addItem(1); // [1]
manualQueue.addItem(2); // [1, 2]
manualQueue.execute(); // logs 1, queue is [2]
manualQueue.getNextItem(); // returns 2, queue is empty
• TValue
new Queuer<TValue>(fn, initialOptions): Queuer<TValue>
new Queuer<TValue>(fn, initialOptions): Queuer<TValue>
Defined in: queuer.ts:250
(item) => void
QueuerOptions<TValue> = {}
Queuer<TValue>
options: QueuerOptions<TValue>;
options: QueuerOptions<TValue>;
Defined in: queuer.ts:247
readonly store: Store<Readonly<QueuerState<TValue>>>;
readonly store: Store<Readonly<QueuerState<TValue>>>;
Defined in: queuer.ts:244
addItem(
item,
position,
runOnItemsChange): boolean
addItem(
item,
position,
runOnItemsChange): boolean
Defined in: queuer.ts:364
Adds an item to the queue. If the queue is full, the item is rejected and onReject is called. Items can be inserted based on priority or at the front/back depending on configuration.
Returns true if the item was added, false if the queue is full.
Example usage:
queuer.addItem('task');
queuer.addItem('task2', 'front');
queuer.addItem('task');
queuer.addItem('task2', 'front');
TValue
QueuePosition = ...
boolean = true
boolean
clear(): void
clear(): void
Defined in: queuer.ts:620
Removes all pending items from the queue. Does not affect items being processed.
void
execute(position?): undefined | TValue
execute(position?): undefined | TValue
Defined in: queuer.ts:485
Removes and returns the next item from the queue and processes it using the provided function.
Example usage:
queuer.execute();
// LIFO
queuer.execute('back');
queuer.execute();
// LIFO
queuer.execute('back');
undefined | TValue
flush(numberOfItems, position?): void
flush(numberOfItems, position?): void
Defined in: queuer.ts:501
Processes a specified number of items to execute immediately with no wait time If no numberOfItems is provided, all items will be processed
number = ...
void
getNextItem(position): undefined | TValue
getNextItem(position): undefined | TValue
Defined in: queuer.ts:444
Removes and returns the next item from the queue without executing the function. Use for manual queue management. Normally, use execute() to process items.
Example usage:
// FIFO
queuer.getNextItem();
// LIFO
queuer.getNextItem('back');
// FIFO
queuer.getNextItem();
// LIFO
queuer.getNextItem('back');
QueuePosition = ...
undefined | TValue
peekAllItems(): TValue[]
peekAllItems(): TValue[]
Defined in: queuer.ts:588
Returns a copy of all items in the queue.
TValue[]
peekNextItem(position): undefined | TValue
peekNextItem(position): undefined | TValue
Defined in: queuer.ts:578
Returns the next item in the queue without removing it.
Example usage:
queuer.peekNextItem(); // front
queuer.peekNextItem('back'); // back
queuer.peekNextItem(); // front
queuer.peekNextItem('back'); // back
QueuePosition = 'front'
undefined | TValue
reset(): void
reset(): void
Defined in: queuer.ts:628
Resets the queuer state to its default values
void
setOptions(newOptions): void
setOptions(newOptions): void
Defined in: queuer.ts:281
Updates the queuer options. New options are merged with existing options.
Partial<QueuerOptions<TValue>>
void
start(): void
start(): void
Defined in: queuer.ts:595
Starts processing items in the queue. If already isRunning, does nothing.
void
stop(): void
stop(): void
Defined in: queuer.ts:605
Stops processing items in the queue. Does not clear the queue.
void
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.