API Reference

p-map

Maps over promises and iterables with bounded concurrency while preserving input order.

Official Documentation ↗
CompatibilityThis documentation covers version p-map v7.x(ESM)/ Node 18 LTS. Check the official docs for the latest API surface.

Installation

npmnpm install p-map
pnpmpnpm add p-map
yarnyarn add p-map

Methods

Overview

p-map runs an async mapper over a collection while capping how many operations are in flight. It is the standard tool for turning an unbounded Promise.all into a rate-controlled batch.

Core Methods

Pass an iterable, a mapper and options. concurrency bounds parallelism, stopOnError controls failure behavior, and pMapSkip omits a result. Input order is preserved in the output.

Usage Notes

Use it whenever you fan out network calls, file reads or database writes, and set concurrency to a value the downstream system tolerates. Combine with p-retry for flaky operations.

Common Pitfalls

The Infinity default can open thousands of connections and exhaust sockets or file descriptors. Concurrency is per call, not global, so parallel pMap calls still multiply load.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/sindresorhus/p-map@latest/readme.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:51:29.804Z. 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

What is the default concurrency?
The default is Infinity, meaning all inputs start at once. Always set an explicit concurrency when the mapper performs network or disk work to avoid overwhelming downstream systems.
Are results in input order?
Yes. pMap preserves the original order of the input, even though tasks may finish out of order, which makes it safe to correlate results with inputs.
How does error handling work?
By default the first rejection rejects the whole call, though already started tasks continue until settled. Set stopOnError: false to collect errors per item instead of failing fast.