Defined in: async-queuer.ts:105
A flexible asynchronous queue that processes tasks with configurable concurrency control.
Features:
Tasks are processed concurrently up to the configured concurrency limit. When a task completes, the next pending task is processed if below the concurrency limit.
const asyncQueuer = new AsyncQueuer<string>({ concurrency: 2 });
asyncQueuer.addItem(async () => {
return 'Hello';
});
asyncQueuer.start();
asyncQueuer.onSuccess((result) => {
console.log(result); // 'Hello'
});
const asyncQueuer = new AsyncQueuer<string>({ concurrency: 2 });
asyncQueuer.addItem(async () => {
return 'Hello';
});
asyncQueuer.start();
asyncQueuer.onSuccess((result) => {
console.log(result); // 'Hello'
});
• TValue
new AsyncQueuer<TValue>(initialOptions): AsyncQueuer<TValue>
new AsyncQueuer<TValue>(initialOptions): AsyncQueuer<TValue>
Defined in: async-queuer.ts:117
AsyncQueuerOptions<TValue> = defaultOptions
AsyncQueuer<TValue>
addItem(
fn,
position,
runOnUpdate): Promise<TValue>
addItem(
fn,
position,
runOnUpdate): Promise<TValue>
Defined in: async-queuer.ts:254
Adds a task to the queuer
() => Promise<TValue> & object
QueuePosition = ...
boolean = true
Promise<TValue>
clear(): void
clear(): void
Defined in: async-queuer.ts:234
Removes all items from the queuer
void
getActiveItems(): () => Promise<TValue>[]
getActiveItems(): () => Promise<TValue>[]
Defined in: async-queuer.ts:386
Returns the active items
() => Promise<TValue>[]
getAllItems(): () => Promise<TValue>[]
getAllItems(): () => Promise<TValue>[]
Defined in: async-queuer.ts:379
Returns a copy of all items in the queuer
() => Promise<TValue>[]
getExecutionCount(): number
getExecutionCount(): number
Defined in: async-queuer.ts:400
Returns the number of items that have been removed from the queuer
number
getIsEmpty(): boolean
getIsEmpty(): boolean
Defined in: async-queuer.ts:358
Returns true if the queuer is empty
boolean
getIsFull(): boolean
getIsFull(): boolean
Defined in: async-queuer.ts:365
Returns true if the queuer is full
boolean
getIsIdle(): boolean
getIsIdle(): boolean
Defined in: async-queuer.ts:421
Returns true if the queuer is running but has no items to process
boolean
getIsRunning(): boolean
getIsRunning(): boolean
Defined in: async-queuer.ts:414
Returns true if the queuer is running
boolean
getNextItem(position): undefined | () => Promise<TValue>
getNextItem(position): undefined | () => Promise<TValue>
Defined in: async-queuer.ts:324
Removes and returns an item from the queuer
QueuePosition = ...
undefined | () => Promise<TValue>
getOptions(): Required<AsyncQueuerOptions<TValue>>
getOptions(): Required<AsyncQueuerOptions<TValue>>
Defined in: async-queuer.ts:142
Returns the current queuer options
Required<AsyncQueuerOptions<TValue>>
getPeek(position): undefined | () => Promise<TValue>
getPeek(position): undefined | () => Promise<TValue>
Defined in: async-queuer.ts:346
Returns an item without removing it
QueuePosition = 'front'
undefined | () => Promise<TValue>
getPendingItems(): () => Promise<TValue>[]
getPendingItems(): () => Promise<TValue>[]
Defined in: async-queuer.ts:393
Returns the pending items
() => Promise<TValue>[]
getRejectionCount(): number
getRejectionCount(): number
Defined in: async-queuer.ts:407
Returns the number of items that have been rejected from the queuer
number
getSize(): number
getSize(): number
Defined in: async-queuer.ts:372
Returns the current size of the queuer
number
onError(cb): () => void
onError(cb): () => void
Defined in: async-queuer.ts:440
Adds a callback to be called when a task errors
(error) => void
Function
void
onSettled(cb): () => void
onSettled(cb): () => void
Defined in: async-queuer.ts:450
Adds a callback to be called when a task is settled
(result) => void
Function
void
onSuccess(cb): () => void
onSuccess(cb): () => void
Defined in: async-queuer.ts:428
Adds a callback to be called when a task succeeds
(result) => void
Function
void
reset(withInitialItems?): void
reset(withInitialItems?): void
Defined in: async-queuer.ts:242
Resets the queuer to its initial state
boolean
void
setOptions(newOptions): AsyncQueuerOptions<TValue>
setOptions(newOptions): AsyncQueuerOptions<TValue>
Defined in: async-queuer.ts:132
Updates the queuer options Returns the new options state
Partial<AsyncQueuerOptions<TValue>>
AsyncQueuerOptions<TValue>
start(): Promise<void>
start(): Promise<void>
Defined in: async-queuer.ts:202
Starts the queuer and processes items
Promise<void>
stop(): void
stop(): void
Defined in: async-queuer.ts:225
Stops the queuer from processing items
void
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.