function useAsyncQueuer<TValue>(fn, options): AsyncQueuer<TValue>
function useAsyncQueuer<TValue>(fn, options): AsyncQueuer<TValue>
Defined in: react-pacer/src/async-queuer/useAsyncQueuer.ts:51
A lower-level React hook that creates an AsyncQueuer instance for managing an async queue of items.
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.
Error Handling:
• TValue
(value) => Promise<any>
AsyncQueuerOptions<TValue> = {}
AsyncQueuer<TValue>
// Basic async queuer for API requests
const asyncQueuer = useAsyncQueuer({
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();
// Basic async queuer for API requests
const asyncQueuer = useAsyncQueuer({
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();
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.