async-pool

Run multiple promise-returning & async functions with limited concurrency using native ES6/ES7

MIT License

Downloads
5.6M
Stars
799
Committers
9
async-pool - v2.1.0 Latest Release

Published by rxaviers over 2 years ago

⭐️ Enhancement

  • Improve the promise consumption logic #44

🐛 Fixes

  • Consume all promises, even if they are fullfilled within the same tick #42
async-pool - v2.0.1

Published by rxaviers over 2 years ago

🐛 Fixes

⚙️ Chore

  • Fix eslint script #37
async-pool - v2.0.0

Published by rxaviers over 2 years ago

🌟 New API (breaking change)

Support for await...of usage by returning an async iterator.

const timeout = ms => new Promise(resolve => setTimeout(() => resolve(ms), ms));

for await (const ms of asyncPool(2, [1000, 5000, 3000, 2000], timeout)) {
  console.log(ms);
}
// Call iterator timeout(1000)
// Call iterator timeout(5000)
// Concurrency limit of 2 reached, wait for the quicker one to complete...
// 1000 finishes
// for await...of outputs "1000"
// Call iterator timeout(3000)
// Concurrency limit of 2 reached, wait for the quicker one to complete...
// 3000 finishes
// for await...of outputs "3000"
// Call iterator timeout(2000)
// Itaration is complete, wait until running ones complete...
// 5000 finishes
// for await...of outputs "5000"
// 2000 finishes
// for await...of outputs "2000"

The main difference: 1.x API waits until all of the promises completes, then all results are returned. The new API (thanks to async iteration) let each result be returned as soon as it completes.

The environment baseline of the new 2.x is ES9 (Node v10). The environment baseline of 1.x is ES6.

async-pool - v1.3.0

Published by rxaviers over 2 years ago

🎉 New Features

  • Support for any iterable, not just array
  • Remove yaassertion dependency

🐛 Fixes

  • Handle unhandled rejection #32