Noisy Pneumatic Mnemonic

    concurrency-control

    1.0.1 • Public • Published

    Concurrency Control

    Make any function that returns a promise a concurrency controlled function. Useful for dealing with rate limiting.

    Installing

    $ npm install concurrency-control

    Example

    Say you need to query an API that implments rate limiting and you have a function that queries it. You could control how many times you execute this function in every place in your project, but it would be better to make it manage its own concurrency and export this controlled function from a module.

    const { getFromApi } = require('myApi')
    const { makeControlled } = require('concurrency-control')
     
    // a concurrency parameter of 1 makes the function secuential
    const MAX_CONCURRENT = 3
    const controlledGetFromApi = makeControlled(getFromApi, { concurrency: MAX_CONCURRENT })
     
    let i = 50
    while (i--) // functions will be executed in batches, never more than 3 at a time
      controlledGetFromApi(i)
        .then(result => { ... })
        .catch(error => { ... })

    Install

    npm i concurrency-control

    DownloadsWeekly Downloads

    2

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    3.84 kB

    Total Files

    4

    Last publish

    Collaborators

    • bernawil