Neverending Programming Mistakes

    concurrent-task-runner

    1.0.1 • Public • Published

    concurrent-task-runner

    Build Status codecov Maintainability Packages npm version

    A lib to run concurrent promises in a controlled pace and number

    How it works?

    It uses P-Queue to control the number of executed promises, but with a more restrictive scenario: all the promises are of the same type

    How to use:

    • Instantiate ConcurrentTaskRunner like this:
    const taskRunner = new ConcurrentTaskRunner(entities, 10, doWork)

    Where doWork is function that receives an element of entities and returns a Promise and 10 is the number of maximum concurrent tasks. Then, just make it run:

    await taskRunner.run();

    That's it! You're done!

    Non parallelizable tasks

    You can indicate to COncurrentTaskRunner that some promises must not be parallelized. How?

    • You need to, first, guarantee that entities is ordered in such a way that all non parallelizable elements are together!
    • Inform a fourth parameter: a function that receives an element of entities and returns an grouping id. This id will be used by ConcurrentTaskRunner to know when the non parallelizable tasks of the current round has ended;
    • doWork can also receives a second parameter: cache. It's starts as an empty object, and you can fill it with whathever you want to use between calls of the non parallelizable sequence;

    Example:

    const taskRunner = new ConcurrentTaskRunner(entities, 10, doWork, (x) => x.groupId);

    Install

    npm i concurrent-task-runner

    DownloadsWeekly Downloads

    4

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    14.1 kB

    Total Files

    13

    Last publish

    Collaborators

    • farenheith