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

createAsyncQueuer

Function: createAsyncQueuer()

ts
function createAsyncQueuer<TValue>(fn, initialOptions): SolidAsyncQueuer<TValue>
function createAsyncQueuer<TValue>(fn, initialOptions): SolidAsyncQueuer<TValue>

Defined in: async-queuer/createAsyncQueuer.ts:130

Creates a Solid-compatible AsyncQueuer instance for managing an asynchronous queue of items, exposing Solid signals for all stateful properties.

Features:

  • Priority queueing via getPriority or item priority property
  • Configurable concurrency limit
  • FIFO (First In First Out) or LIFO (Last In First Out) queue behavior
  • Pause/resume processing
  • Task cancellation
  • Item expiration
  • Lifecycle callbacks for success, error, settled, items change, etc.
  • All stateful properties (active items, pending items, counts, etc.) are exposed as Solid signals for reactivity

Tasks are processed concurrently up to the configured concurrency limit. When a task completes, the next pending task is processed if the concurrency limit allows.

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

Example usage:

tsx
// Basic async queuer for API requests
const asyncQueuer = createAsyncQueuer(async (item) => {
  // process item
  return await fetchData(item);
}, {
  initialItems: [],
  concurrency: 2,
  maxSize: 100,
  started: false,
  onSuccess: (result) => {
    console.log('Item processed:', result);
  },
  onError: (error) => {
    console.error('Processing failed:', error);
  }
});

// Add items to queue
asyncQueuer.addItem(newItem);

// Start processing
asyncQueuer.start();

// Use Solid signals in your UI
const pending = asyncQueuer.pendingItems();
// Basic async queuer for API requests
const asyncQueuer = createAsyncQueuer(async (item) => {
  // process item
  return await fetchData(item);
}, {
  initialItems: [],
  concurrency: 2,
  maxSize: 100,
  started: false,
  onSuccess: (result) => {
    console.log('Item processed:', result);
  },
  onError: (error) => {
    console.error('Processing failed:', error);
  }
});

// Add items to queue
asyncQueuer.addItem(newItem);

// Start processing
asyncQueuer.start();

// Use Solid signals in your UI
const pending = asyncQueuer.pendingItems();

Type Parameters

TValue

Parameters

fn

(value) => Promise<any>

initialOptions

AsyncQueuerOptions<TValue> = {}

Returns

SolidAsyncQueuer<TValue>

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.