Framework
Version
Debouncer API Reference
Throttler API Reference
Rate Limiter API Reference
Queue API Reference

AsyncQueuer

Class: AsyncQueuer<TValue>

Defined in: async-queuer.ts:95

A flexible asynchronous queuer that processes tasks with configurable concurrency control.

Features:

  • Priority queuer support via getPriority option
  • Configurable concurrency limit
  • Task success/error/completion callbacks
  • FIFO (First In First Out) or LIFO (Last In First Out) queuer behavior
  • Pause/resume task processing
  • Task cancellation

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.

Example

ts
const queuer = new AsyncQueuer<string>({ concurrency: 2 });

queuer.addItem(async () => {
  return 'Hello';
});

queuer.start();

queuer.onSuccess((result) => {
  console.log(result); // 'Hello'
});
const queuer = new AsyncQueuer<string>({ concurrency: 2 });

queuer.addItem(async () => {
  return 'Hello';
});

queuer.start();

queuer.onSuccess((result) => {
  console.log(result); // 'Hello'
});

Type Parameters

• TValue

Constructors

new AsyncQueuer()

ts
new AsyncQueuer<TValue>(initialOptions): AsyncQueuer<TValue>
new AsyncQueuer<TValue>(initialOptions): AsyncQueuer<TValue>

Defined in: async-queuer.ts:106

Parameters

initialOptions

AsyncQueuerOptions<TValue> = defaultOptions

Returns

AsyncQueuer<TValue>

Properties

options

ts
protected options: Required<AsyncQueuerOptions<TValue>>;
protected options: Required<AsyncQueuerOptions<TValue>>;

Defined in: async-queuer.ts:96

Methods

addItem()

ts
addItem(
   fn, 
   position, 
runOnUpdate): Promise<TValue>
addItem(
   fn, 
   position, 
runOnUpdate): Promise<TValue>

Defined in: async-queuer.ts:184

Adds a task to the queuer

Parameters

fn

() => Promise<TValue> & object

position

QueuePosition = ...

runOnUpdate

boolean = true

Returns

Promise<TValue>


clear()

ts
clear(): void
clear(): void

Defined in: async-queuer.ts:305

Removes all items from the queuer

Returns

void


getActiveItems()

ts
getActiveItems(): () => Promise<TValue>[]
getActiveItems(): () => Promise<TValue>[]

Defined in: async-queuer.ts:339

Returns the active items

Returns

() => Promise<TValue>[]


getAllItems()

ts
getAllItems(): () => Promise<TValue>[]
getAllItems(): () => Promise<TValue>[]

Defined in: async-queuer.ts:325

Returns a copy of all items in the queuer

Returns

() => Promise<TValue>[]


getExecutionCount()

ts
getExecutionCount(): number
getExecutionCount(): number

Defined in: async-queuer.ts:332

Returns the number of items that have been removed from the queuer

Returns

number


getNextItem()

ts
getNextItem(position): undefined | () => Promise<TValue>
getNextItem(position): undefined | () => Promise<TValue>

Defined in: async-queuer.ts:252

Removes and returns an item from the queuer

Parameters

position

QueuePosition = ...

Returns

undefined | () => Promise<TValue>


getPendingItems()

ts
getPendingItems(): () => Promise<TValue>[]
getPendingItems(): () => Promise<TValue>[]

Defined in: async-queuer.ts:346

Returns the pending items

Returns

() => Promise<TValue>[]


isEmpty()

ts
isEmpty(): boolean
isEmpty(): boolean

Defined in: async-queuer.ts:284

Returns true if the queuer is empty

Returns

boolean


isFull()

ts
isFull(): boolean
isFull(): boolean

Defined in: async-queuer.ts:291

Returns true if the queuer is full

Returns

boolean


isIdle()

ts
isIdle(): boolean
isIdle(): boolean

Defined in: async-queuer.ts:422

Returns true if the queuer is running but has no items to process

Returns

boolean


isRunning()

ts
isRunning(): boolean
isRunning(): boolean

Defined in: async-queuer.ts:415

Returns true if the queuer is running

Returns

boolean


onError()

ts
onError(cb): () => void
onError(cb): () => void

Defined in: async-queuer.ts:363

Adds a callback to be called when a task errors

Parameters

cb

(error) => void

Returns

Function

Returns

void


onSettled()

ts
onSettled(cb): () => void
onSettled(cb): () => void

Defined in: async-queuer.ts:373

Adds a callback to be called when a task is settled

Parameters

cb

(result) => void

Returns

Function

Returns

void


onSuccess()

ts
onSuccess(cb): () => void
onSuccess(cb): () => void

Defined in: async-queuer.ts:353

Adds a callback to be called when a task succeeds

Parameters

cb

(result) => void

Returns

Function

Returns

void


peek()

ts
peek(position): undefined | () => Promise<TValue>
peek(position): undefined | () => Promise<TValue>

Defined in: async-queuer.ts:274

Returns an item without removing it

Parameters

position

QueuePosition = 'front'

Returns

undefined | () => Promise<TValue>


reset()

ts
reset(withInitialItems?): void
reset(withInitialItems?): void

Defined in: async-queuer.ts:313

Resets the queuer to its initial state

Parameters

withInitialItems?

boolean

Returns

void


setOptions()

ts
setOptions(newOptions): AsyncQueuerOptions<TValue>
setOptions(newOptions): AsyncQueuerOptions<TValue>

Defined in: async-queuer.ts:121

Updates the queuer options Returns the new options state

Parameters

newOptions

Partial<AsyncQueuerOptions<TValue>>

Returns

AsyncQueuerOptions<TValue>


size()

ts
size(): number
size(): number

Defined in: async-queuer.ts:298

Returns the current size of the queuer

Returns

number


start()

ts
start(): Promise<void>
start(): Promise<void>

Defined in: async-queuer.ts:383

Starts the queuer and processes items

Returns

Promise<void>


stop()

ts
stop(): void
stop(): void

Defined in: async-queuer.ts:406

Stops the queuer from processing items

Returns

void


tick()

ts
protected tick(): void
protected tick(): void

Defined in: async-queuer.ts:131

Processes items in the queuer

Returns

void

Subscribe to Bytes

Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.

Bytes

No spam. Unsubscribe at any time.