File: Queuer.md | Updated: 11/15/2025
Search...
+ K
Auto
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide
Documentation
Framework
React
Version
Latest
Search...
+ K
Menu
Getting Started
Guides
API Reference
Debouncer API Reference
Throttler API Reference
Rate Limiter API Reference
Queue API Reference
Batcher API Reference
Debouncer Examples
Throttler Examples
Rate Limiter Examples
Queue Examples
Batcher Examples
TanStack Query Examples
Framework
React
Version
Latest
Menu
Getting Started
Guides
API Reference
Debouncer API Reference
Throttler API Reference
Rate Limiter API Reference
Queue API Reference
Batcher API Reference
Debouncer Examples
Throttler Examples
Rate Limiter Examples
Queue Examples
Batcher Examples
TanStack Query Examples
On this page
Copy Markdown
Class: Queuer<TValue>
=====================
Defined in: queuer.ts:269
A flexible queue that processes items with configurable wait times, expiration, and priority.
This synchronous version is lighter weight and often all you need - upgrade to AsyncQueuer when you need promises, retry support, abort capabilities, concurrent execution, or advanced error handling.
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:
ts
// 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, queuer) => 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, queuer) => 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
Type Parameters
---------------
### TValue
TValue
Constructors
------------
### Constructor
ts
new Queuer<TValue>(fn, initialOptions): Queuer<TValue>;
new Queuer<TValue>(fn, initialOptions): Queuer<TValue>;
Defined in: queuer.ts:277
(item) => void
QueuerOptions <TValue> = {}
Queuer<TValue>
Properties
----------
### fn()
ts
fn: (item) => void;
fn: (item) => void;
Defined in: queuer.ts:278
TValue
void
ts
key: string | undefined;
key: string | undefined;
Defined in: queuer.ts:273
ts
options: QueuerOptions<TValue>;
options: QueuerOptions<TValue>;
Defined in: queuer.ts:274
ts
readonly store: Store<Readonly<QueuerState<TValue>>>;
readonly store: Store<Readonly<QueuerState<TValue>>>;
Defined in: queuer.ts:270
ts
addItem(
item,
position,
runOnItemsChange): boolean;
addItem(
item,
position,
runOnItemsChange): boolean;
Defined in: queuer.ts:399
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:
ts
queuer.addItem('task');
queuer.addItem('task2', 'front');
queuer.addItem('task');
queuer.addItem('task2', 'front');
TValue
QueuePosition = ...
boolean = true
boolean
ts
clear(): void;
clear(): void;
Defined in: queuer.ts:681
Removes all pending items from the queue. Does not affect items being processed.
void
ts
execute(position?): TValue | undefined;
execute(position?): TValue | undefined;
Defined in: queuer.ts:535
Removes and returns the next item from the queue and processes it using the provided function.
Example usage:
ts
queuer.execute();
// LIFO
queuer.execute('back');
queuer.execute();
// LIFO
queuer.execute('back');
#### Parameters ##### position?
TValue | undefined
ts
flush(numberOfItems, position?): void;
flush(numberOfItems, position?): void;
Defined in: queuer.ts:551
Processes a specified number of items to execute immediately with no wait time If no numberOfItems is provided, all items will be processed
#### Parameters ##### numberOfItems
number = ...
void
ts
flushAsBatch(batchFunction): void;
flushAsBatch(batchFunction): void;
Defined in: queuer.ts:566
Processes all items in the queue as a batch using the provided function as an argument The queue is cleared after processing
#### Parameters ##### batchFunction
(items) => void
void
ts
getNextItem(position): TValue | undefined;
getNextItem(position): TValue | undefined;
Defined in: queuer.ts:483
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:
ts
// FIFO
queuer.getNextItem();
// LIFO
queuer.getNextItem('back');
// FIFO
queuer.getNextItem();
// LIFO
queuer.getNextItem('back');
#### Parameters ##### position
QueuePosition = ...
TValue | undefined
ts
peekAllItems(): TValue[];
peekAllItems(): TValue[];
Defined in: queuer.ts:649
Returns a copy of all items in the queue.
TValue[]
ts
peekNextItem(position): TValue | undefined;
peekNextItem(position): TValue | undefined;
Defined in: queuer.ts:639
Returns the next item in the queue without removing it.
Example usage:
ts
queuer.peekNextItem(); // front
queuer.peekNextItem('back'); // back
queuer.peekNextItem(); // front
queuer.peekNextItem('back'); // back
#### Parameters ##### position
QueuePosition = 'front'
TValue | undefined
ts
reset(): void;
reset(): void;
Defined in: queuer.ts:689
Resets the queuer state to its default values
void
ts
setOptions(newOptions): void;
setOptions(newOptions): void;
Defined in: queuer.ts:315
Updates the queuer options. New options are merged with existing options.
#### Parameters ##### newOptions
Partial<QueuerOptions <TValue>>
void
ts
start(): void;
start(): void;
Defined in: queuer.ts:656
Starts processing items in the queue. If already isRunning, does nothing.
void
ts
stop(): void;
stop(): void;
Defined in: queuer.ts:666
Stops processing items in the queue. Does not clear the queue.
void
