Creates an instance of ParallelLoop.
Add job into pool
Name of job
Function that will be triggered
Padding time between executions
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
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 a job by a given name
Name of job
Remove listeners for a given eventName
otherwise all listeners
Name of event
Fake .resolve() method of Promise
Value to return in .then()
Start parallel loop
Stop parallel loop
Fake .then() method of Promise
Callback function which will be triggered after .resolve()
Generated using TypeDoc
Introduction
ParallelLoop allowed you to trigger all jobs separately, It guarantees that, the same job won't be trigger twice but different jobs will be happened at the same time.
Example code
import { TimeDuration, ParallelLoop } from 'noqueue'; const iParallelLoop = new ParallelLoop(); iParallelLoop .add( 'job-1', async () => { return 'job-1-result'; }, TimeDuration.fromSecond(5), ) .add( 'job-2', async () => { return 'job-2-result'; }, TimeDuration.fromSecond(1), ); iParallelLoop.on('success', (eventName, ...params: any[]) => { console.log(`Event ${eventName} completed with result:`, params); }); iParallelLoop.on('error', (eventName, error) => { console.log(`Event ${eventName} failed with error:`, error); }); iParallelLoop.start();
Result:
As you see, padding time between
job-2
is 5 seconds that's whyjob-1
will be triggered after 5 times ofjob-2
.