at-a-time
at-a-time
allows you to do do asynchronous operations simultaneously but with a max number of operations going at any one time.
Why?
Promise.all()
allows you to simultaneously do asynchronous operations and a for
loop in an async function allows you to sequentially do asynchronous operations. But, sometimes you have more operations than you can handle at once and it would take too long to handle them sequentially. at-a-time
allows you to do do asynchronous operations simultaneously but with a max number of operations going at any one time.
Installation
$ npm install at-a-time
Usage
// import libraryconst atATime = ; const endpoints = 'https://api.something.com/12345' 'https://api.something.com/23451' 'https://api.something.com/34512' 'https://api.something.com/45123' 'https://api.something.com/51234' 'https://api.something.com/23456' 'https://api.something.com/62345' 'https://api.something.com/56234' 'https://api.something.com/45623' 'https://api.something.com/34562'; // create an array of Promise-returning functionsconst operations = endpoints ; // Work through the operations keeping two// simultaneous operations going at a time. // Usage with manual Promise handling ; // Usage within an sync function { try const res = await ; console; // array of responses in order catcherr // handle error }; // Usage within a generator function;
Running Tests
$ npm install
$ npm test
License
Apache License Version 2.0