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

asyncQueue

Function: asyncQueue()

ts
function asyncQueue<TFn>(options): (fn, position, runOnItemsChange) => void
function asyncQueue<TFn>(options): (fn, position, runOnItemsChange) => void

Defined in: async-queuer.ts:590

Creates a new AsyncQueuer instance with the given options and returns a bound addItem function. The queuer is automatically started and ready to process items.

Error Handling:

  • If an onError handler is provided, it will be called with the error and queuer instance
  • If throwOnError is true (default when no onError handler is provided), the error will be thrown
  • If throwOnError is false (default when onError handler is provided), the error will be swallowed
  • Both onError and throwOnError can be used together - the handler will be called before any error is thrown
  • The error state can be checked using the underlying AsyncQueuer instance

Type Parameters

TFn extends AsyncQueuerFn

Parameters

options

AsyncQueuerOptions<TFn>

Configuration options for the AsyncQueuer

Returns

Function

A bound addItem function that can be used to add tasks to the queuer

Adds a task to the queuer

Parameters

fn

TFn

position

QueuePosition = ...

runOnItemsChange

boolean = true

Returns

void

Example

ts
const enqueue = asyncQueue<string>();

// Add items to be processed
enqueue(async () => {
  return 'Hello';
});
const enqueue = asyncQueue<string>();

// Add items to be processed
enqueue(async () => {
  return 'Hello';
});
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.