Defined in: queuer.ts:112
A flexible queue data structure that defaults to FIFO (First In First Out) behavior with optional position overrides for stack-like or double-ended operations.
The queuer can automatically process items as they are added, with configurable wait times between processing each item. Processing can be started/stopped and the queuer will maintain its state.
Supports priority-based ordering when a getPriority function is provided. Items with higher priority values will be processed first.
Default queue behavior:
Stack (LIFO) behavior:
Double-ended queuer behavior:
Processing behavior:
// FIFO queuer
const queuer = new Queuer<number>();
queuer.addItem(1); // [1]
queuer.addItem(2); // [1, 2]
queuer.getNextItem(); // returns 1, queuer is [2]
// Priority queuer with processing
const priorityQueue = new Queuer<number>({
getPriority: (n) => n, // Higher numbers have priority
started: true, // Begin processing immediately
wait: 1000, // Wait 1s between items
onGetNextItem: (item) => console.log(item)
});
priorityQueue.addItem(1); // [1]
priorityQueue.addItem(3); // [3, 1] - 3 processed first
priorityQueue.addItem(2); // [3, 2, 1]
// FIFO queuer
const queuer = new Queuer<number>();
queuer.addItem(1); // [1]
queuer.addItem(2); // [1, 2]
queuer.getNextItem(); // returns 1, queuer is [2]
// Priority queuer with processing
const priorityQueue = new Queuer<number>({
getPriority: (n) => n, // Higher numbers have priority
started: true, // Begin processing immediately
wait: 1000, // Wait 1s between items
onGetNextItem: (item) => console.log(item)
});
priorityQueue.addItem(1); // [1]
priorityQueue.addItem(3); // [3, 1] - 3 processed first
priorityQueue.addItem(2); // [3, 2, 1]
• TValue
new Queuer<TValue>(initialOptions): Queuer<TValue>
new Queuer<TValue>(initialOptions): Queuer<TValue>
Defined in: queuer.ts:120
QueuerOptions<TValue> = defaultOptions
Queuer<TValue>
protected options: Required<QueuerOptions<TValue>>;
protected options: Required<QueuerOptions<TValue>>;
Defined in: queuer.ts:113
addItem(
item,
position,
runOnUpdate): boolean
addItem(
item,
position,
runOnUpdate): boolean
Defined in: queuer.ts:172
Adds an item to the queuer and starts processing if not already running
TValue
QueuePosition = ...
boolean = true
boolean
true if item was added, false if queuer is full
clear(): void
clear(): void
Defined in: queuer.ts:286
Removes all items from the queuer
void
getAllItems(): TValue[]
getAllItems(): TValue[]
Defined in: queuer.ts:306
Returns a copy of all items in the queuer
TValue[]
getExecutionCount(): number
getExecutionCount(): number
Defined in: queuer.ts:313
Returns the number of items that have been removed from the queuer
number
getNextItem(position): undefined | TValue
getNextItem(position): undefined | TValue
Defined in: queuer.ts:223
Removes and returns an item from the queuer using shift (default) or pop
QueuePosition = ...
undefined | TValue
// Standard FIFO queuer
queuer.getNextItem()
// Stack-like behavior (LIFO)
queuer.getNextItem('back')
// Standard FIFO queuer
queuer.getNextItem()
// Stack-like behavior (LIFO)
queuer.getNextItem('back')
isEmpty(): boolean
isEmpty(): boolean
Defined in: queuer.ts:265
Returns true if the queuer is empty
boolean
isFull(): boolean
isFull(): boolean
Defined in: queuer.ts:272
Returns true if the queuer is full
boolean
isIdle(): boolean
isIdle(): boolean
Defined in: queuer.ts:358
Returns true if the queuer is running but has no items to process
boolean
isRunning(): boolean
isRunning(): boolean
Defined in: queuer.ts:351
Returns true if the queuer is running
boolean
onUpdate(cb): () => void
onUpdate(cb): () => void
Defined in: queuer.ts:320
Adds a callback to be called when an item is processed
(item) => void
Function
void
peek(position): undefined | TValue
peek(position): undefined | TValue
Defined in: queuer.ts:253
Returns an item without removing it
QueuePosition = ...
undefined | TValue
// Look at next item to getNextItem
queuer.peek()
// Look at last item (like stack top)
queuer.peek('back')
// Look at next item to getNextItem
queuer.peek()
// Look at last item (like stack top)
queuer.peek('back')
reset(withInitialItems?): void
reset(withInitialItems?): void
Defined in: queuer.ts:294
Resets the queuer to its initial state
boolean
void
setOptions(newOptions): QueuerOptions<TValue>
setOptions(newOptions): QueuerOptions<TValue>
Defined in: queuer.ts:161
Updates the queuer options Returns the new options state
Partial<QueuerOptions<TValue>>
QueuerOptions<TValue>
size(): number
size(): number
Defined in: queuer.ts:279
Returns the current size of the queuer
number
start(): void
start(): void
Defined in: queuer.ts:339
Starts the queuer and processes items
void
stop(): void
stop(): void
Defined in: queuer.ts:330
Stops the queuer from processing items
void
protected tick(): void
protected tick(): void
Defined in: queuer.ts:134
Processes items in the queuer
void
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.