API Reference

Async.js

Utility module providing callback-style control flow helpers such as parallel, series, waterfall, and eachLimit.

Official Documentation ↗
CompatibilityThis documentation covers version v3. Check the official docs for the latest API surface.

Installation

npmnpm install async
pnpmpnpm add async

Methods

Overview

Async.js provides callback-style control flow helpers such as parallel, series, waterfall, and eachLimit for coordinating async work. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.

Core APIs

  • async.parallel — Runs independent tasks concurrently and collects their results keyed by task name.
  • async.series — Runs tasks strictly in order, passing each result to the final callback.
  • async.eachLimit — Iterates items with at most the given number of concurrent iteratee calls.

Example

const async = require('async');

async.parallel({
  users: (cb) => fetchUsers().then((r) => cb(null, r), cb),
  posts: (cb) => fetchPosts().then((r) => cb(null, r), cb),
}, (err, results) => {
  if (err) throw err;
  console.log(results.users);
});

Notes

Error propagation is fail-fast but does not cancel in-flight tasks, so design tasks to be safe if others fail. Promise variants exist for modern code.

Verification

Run async.series with two tasks and confirm the second only executes after the first callback fires.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://caolan.github.io/async/v3/docs.html · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:48:13.021Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

FAQ

How do I mix Async.js with promises?
Async.js also exposes promise-returning variants such as async.mapLimit; use those to avoid wrapping callbacks manually.
What happens when a task errors in parallel?
By default the callback fires once with the first error; other in-flight tasks keep running, so guard shared state.
How do I run tasks with dependencies between them?
Use async.waterfall to pass each result to the next function, or async.auto to declare dependency names.