p-map
Maps over promises and iterables with bounded concurrency while preserving input order.
Official Documentation ↗p-map v7.x(ESM)/ Node 18 LTS. Check the official docs for the latest API surface.Installation
npm install p-mappnpm add p-mapyarn add p-mapMethods
No methods match this filter.
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.
- This is different from Promise.all() in that you can control the concurrency and also decide whether or not to stop iterating when there’s an error. (https://cdn.jsdelivr.net/gh/sindresorhus/p-map@latest/readme.md)
- The returned Promise still rejects when iterating input throws, like Promise.allSettled(), and when the signal aborts. (https://cdn.jsdelivr.net/gh/sindresorhus/p-map@latest/readme.md)
- With a finite concurrency, a promise that rejects before pMapSettled reaches it is reported as an unhandled rejection. (https://cdn.jsdelivr.net/gh/sindresorhus/p-map@latest/readme.md)
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.