npm install many-promises
;const items = 1 2 3 4 5 6 7 8 9 10;const job = Promise;const results = await ;// Will call `job` for every `item` in `items` and await until all promises are resolved.// results - [2, 4, 6, 8, 10, 12, 14, 16, 18, 20];
// All promises in parallel:const results = await ;// All promises sequentially:const results = await ;// Maximum 3 jobs at the same time, but each job has a minimum 200ms duration:const results = await ;
Note: Types ItemType and ResultType are usually inferred and you don't need to specify them explicitly.
Array of items of any type.
A function with one argument - which is an item from the
Maximum number of Promises that can be in progress at the same time.
Minimum time of execution for one job. If a job finishes earlier, next job will wait for this timeout to end before starting.