1.1.1 • Published 4 years ago
jobbel v1.1.1
Jobbel - async job manager
Jobbel is a lightweight job manager that can handle a limited concurrent jobs.
Usage
The API of jobbel allows for three different parameters:
concurrent: number
: the number of concurrent async jobs that can run simultaneously;onResolve?: (result, status)
: a function that is triggered in resolving each job. The result of the job and the (new) status of jobbel are given as parameters;onReject?: (result, status)
: a function that is triggered in rejecting each job. The result of the job and the (new) status of jobbel are given as parameters;
import jobbel from 'jobbel';
function resolve(result, state) { ... }
function reject(error, state) { ... }
const manager = jobbel({ concurrent: 3, onResolve: resolve, onReject: reject });
// .push requires (async) functions as input
manager.push(...myAsyncApiCallFunctions);
...
console.log(manager.status); // { pending: 0, resolved: x, rejected: y }
In the resolve
and reject
callback functions, the second parameter shows the current state of the job manager. It holds the following properties:
pending
: the amount of jobs currently running. If this is0
the job manager is finished;resolved
: the amount of jobs successfully finished;rejected
: the amount of jobs failed;.