function useAsyncQueuer<TFn>(options): AsyncQueuer<TFn>
function useAsyncQueuer<TFn>(options): AsyncQueuer<TFn>
Defined in: react-pacer/src/async-queuer/useAsyncQueuer.ts:54
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:
• TFn extends AsyncQueuerFn
AsyncQueuerOptions<TFn> = {}
AsyncQueuer<TFn>
// 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.