
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
@toolbuilder/await-for-it
Advanced tools
Concurrency using chainable async iterables, such as task pool, event queue, pub/sub, merge, chunk, throttle, etc.
Await-For-It implements common concurrency patterns using async iterables. The iterables are chainable for ease of use. Or you can use the async generators on their own with the functional, data-last API.
n tasks at a time: PoolIf you just want synchronous iterables try IterableFu.
npm install --save @toolbuilder/await-for-it
If you want the chainable API, use this import.
import { chainable } from '@toolbuilder/await-for-it'
If you want the functional API, use this import.
import { generators, transforms, reducers } from '@toolbuilder/await-for-it'
Users of both API styles will probably want other methods and classes from the main package such as:
import { Poll, Queue, callWithTimeout } from '@toolbuilder/await-for-it'
The chainable API is dynamically created from the functional API when Await-For-It is loaded. Underneath, the methods are the same.
The documentation is in progress. Sometimes the functional API examples show chainable API use. Sometimes it is the other way around. I will continue improving - especially in areas where you provide feedback.
Await-For-It works with your generators and iterables. It is also possible to add or remove methods from Await-For-It to suit your needs. See customization.
Here is a quick set of examples
After the 1.0.0 changes, there should be no breaking changes going forward.
1.0.0 -
Queue no longer throws QueueFull when the buffer reaches capacity. That's properly the buffer's job.Queue constructor no longer accepts a Number to specify buffer capacity. The constructor only accepts a buffer.Queue the default buffer is an empty Array although that is probably not what you want.Queue no longer provides a capacity propertyRingBuffer is no longer exported by Await-For-It. It is now here.Semaphore and Mutex are no longer exported by Await-For-It. If you really need them they are here.Await-For-It is focused on solving common asynchronous patterns with asynchronous iterables. There are many other packages that solve common asynchronous patterns without async iterables. There are also a number of packages that provide async iterable support, but don't seem to fully support async concurrency patterns.
There are lots of packages that support synchronous iterables, but that doesn't help with concurrency. For example, Iterablefu is the synchronous version of Await-For-It.
There are popular Observable libraries. I worked with RxJs and Kefir before writing Await-For-It. After working with both, I strongly prefer async generators and iterators to Observables. Here's why:
Observables is extra work.yield *, async functions, Promises, etc.Observables use a push model, and async iterables use a pull model. Await-For-It provides Queue to bridge from push to pull. You might also look at emittery.
Node streams are now async iterables, so this isn't an either/or decision. The pipeline method might be all you need.
Promise chains work just fine if you don't need to control the number of active tasks, or need to run the tasks sequentially.
for await loops are perfect when you don't need to relax that 'one-at-a-time' behavior. But when you refactor a bunch of nested loops they'll look a lot like the functional or chainable API of Await-For-It.
Contributions are welcome. Please create a pull request.
pnpm testnpm install -g pnpmpnpm installpnpm run check:packfile to test against Node ES and CommonJS projects, as well as Electron.pnpm run check to validate the package is ready for commitThis project uses Github issues.
MIT
FAQs
Concurrency using chainable async iterables, such as task pool, event queue, pub/sub, merge, chunk, throttle, etc.
We found that @toolbuilder/await-for-it demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
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.

Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.

Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.

Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.