Repo of the Day
caolan/async
Published: Mar 23, 2024
Open repository ↗Async utilities for node and the browser
Summary
Async is a JavaScript utility module for working with asynchronous code. It provides a collection of functions for coordinating async operations such as iterating over collections, limiting concurrency, and chaining callbacks. It works in both Node.js and the browser, and ships with CommonJS and ESM builds.
What it is useful for
Async helps when you need to coordinate multiple asynchronous operations without writing nested callbacks or hand-rolling Promise.all chains. Concrete scenarios shown in the README include:
- Reading many files into a keyed object. The first example uses
async.forEachOfto walk over an object map of config file paths (dev,test,prod), parse each one, and collect the results into aconfigsobject keyed by name — with errors short-circuiting through a single final callback. - Fetching URLs with a concurrency cap. The second example uses
async.mapLimitto fetch up to 5 URLs at a time usingfetchandawait, then gathers the response bodies into a single results array.
More broadly, the library covers collection helpers (each, map, filter, reduce), control flow primitives (series, parallel, waterfall), and queues, all built around Node-style callbacks while still accepting async/await functions as task inputs.
How engineers can use it
The README documents a simple setup for Node.js:
npm i async
Then in CommonJS:
var async = require("async");
An ESM/MJS build is included in the main async package and is automatically picked up by bundlers like Webpack or Rollup. For projects that want a pure ESM build, the README points to the separate async-es package on npm. Full API documentation lives at https://caolan.github.io/async/.
A few practical notes from the README worth keeping in mind:
- Async is callback-based at its core, but it accepts
asyncfunctions as task inputs, so you can mix modern syntax with the control-flow helpers (as themapLimitexample demonstrates). - The README does not spell out non-bundler browser installation steps beyond saying the library "can also be used directly in the browser," so for plain
<script>use you would need to consult the docs site. - The project is MIT licensed.
Old Async v1.5.x documentation is preserved in the repository for users still on that line, while the current docs reflect the newer API.