Creates an instance of QueueLoop.
Configuration that used to overwrite default configurations
Event will be emitted after one job is failed.
Event will be emitted after one job is completed.
Add job into queue and await for processing
Name of job
Job will be added to queue
Fake .catch() method of Promise
Callback function which will be triggered after .reject()
Emit an event to listeners
Event name
Parameters that we need to emit to listeners
Get all event names
Array of event names
Get current working job
Get list of job's name
Add new event listener
Event name
Callback that will be triggered if event emitted
Add event listener for one time event
Event name
Callback that will be triggered if event emitted
Fake .reject() method of Promise
Error to return in .catch()
Remove one job from queue by given name
Remove job from queue
Remove listeners for a given eventName
otherwise all listeners
Name of event
Fake .resolve() method of Promise
Value to return in .then()
Start queue loop
Stop queue loop
Fake .then() method of Promise
Callback function which will be triggered after .resolve()
Generated using TypeDoc
Introduction
QueueLoop allowed you do jobs by sequence and repeat them just one by one till the loop was stopped by invoke QueueLoop.stop
Example code
We add three jobs to the queue and start processing.
import { QueueLoop, TimeDuration } from 'noqueue'; const iQueueLoop = new QueueLoop(); iQueueLoop .add( 'job-1', async () => { return ['job-1-result']; }, TimeDuration.fromSecond(2), // After job-1 is done, wait for 2 seconds ) .add( 'job-2', async (job1Result: string) => { console.log('Processing job-1 with input params:', { job1Result }); }, TimeDuration.fromSecond(10), // After job-1 is done, wait for 10 seconds ) .add( 'job-3', async () => { throw new Error('This an annoying error'); }, TimeDuration.fromSecond(2), // After job-3 is done, wait for 2 seconds ); // Listen on success event iQueueLoop.on('success', (eventName, ...params: any[]) => { console.log(`Event ${eventName} completed with result:`, params); }); // Listen on error event iQueueLoop.on('error', (eventName, error) => { console.log(`Event ${eventName} failed with error:`, error); }); iQueueLoop.start();
Here is the result:
Even there are an error, it won't break the loop. QueueLoop is just keep moving on.