Socket
Socket
Sign inDemoInstall

concurrent-task-runner

Package Overview
Dependencies
4
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    concurrent-task-runner

A lib to run concurrent tasks in a controlled pace


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Install size
96.2 kB
Created
Weekly downloads
 

Readme

Source

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);

Keywords

FAQs

Last updated on 15 Jan 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc