# sindresorhus/p-map architecture

> Architecture diagram of the GitHub repository sindresorhus/p-map, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sindresorhus/p-map
- Repository: https://github.com/sindresorhus/p-map
- Video tour (about a minute): https://gitdiagram.com/sindresorhus/p-map/video

## Overview

p-map is a small runtime library for mapping synchronous or asynchronous iterables concurrently. Its principal workflow accepts an input and mapper, applies concurrency and error/control policies, then returns an ordered collection or a streaming async iterable. The README documents array and keyed variants, settled results, skip/stop controls, abort signals, and streaming with backpressure. Those variants are API-level capabilities implemented in the shared runtime file; the excerpts do not expose every internal call boundary, so unverified links are dashed.

Main entry points: [`index.js`](https://github.com/sindresorhus/p-map/blob/main/index.js) (pMap)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mapping["Concurrent Mapping"]
  node_pmap["pMap<br/>[index.js]"]
  node_concurrent_engine["Concurrent Engine<br/>[index.js]"]
end

subgraph group_streaming["Streaming"]
  node_iterable["pMapIterable<br/>[index.js]"]
  node_iterator["Iterator Pulling<br/>[index.js]"]
  node_stream_queue["Stream Buffer<br/>[index.js]"]
end

subgraph group_policies["Result Policies"]
  node_settled["pMapSettled<br/>[index.js]"]
  node_keyed["Keyed Mapping<br/>[index.js]"]
  node_keyed_settled["Settled Keyed<br/>[index.js]"]
  node_skip_stop["Skip / Stop Controls<br/>[index.js]"]
  node_abort["Abort Signal"]
end

node_caller(("Library Caller"))
node_input["Iterable Input"]
node_mapper["Mapper Function"]
node_results["Mapped Results"]

node_caller -->|"invokes"| node_pmap
node_caller -->|"invokes"| node_settled
node_caller -->|"invokes"| node_keyed
node_caller -->|"invokes"| node_keyed_settled
node_caller -->|"invokes"| node_iterable
node_input -->|"supplies items"| node_pmap
node_mapper -->|"maps items"| node_pmap
node_pmap -->|"delegates"| node_concurrent_engine
node_settled -.->|"delegates"| node_concurrent_engine
node_keyed -->|"maps entries"| node_concurrent_engine
node_keyed_settled -.->|"maps entries"| node_concurrent_engine
node_input -->|"supplies items"| node_iterable
node_mapper -->|"maps items"| node_iterable
node_iterable -->|"pulls from"| node_iterator
node_iterator -->|"fills slots"| node_stream_queue
node_concurrent_engine -->|"calls concurrently"| node_mapper
node_concurrent_engine -.->|"handles controls"| node_skip_stop
node_pmap -->|"accepts signal"| node_abort
node_iterable -->|"yields buffered"| node_stream_queue
node_pmap -->|"returns promise"| node_results
node_settled -->|"returns settled"| node_results
node_keyed -->|"returns keyed"| node_results
node_keyed_settled -->|"returns settled keys"| node_results
node_iterable -->|"streams values"| node_results

click node_pmap "https://github.com/sindresorhus/p-map/blob/main/index.js"
click node_settled "https://github.com/sindresorhus/p-map/blob/main/index.js"
click node_keyed "https://github.com/sindresorhus/p-map/blob/main/index.js"
click node_keyed_settled "https://github.com/sindresorhus/p-map/blob/main/index.js"
click node_concurrent_engine "https://github.com/sindresorhus/p-map/blob/main/index.js"
click node_iterable "https://github.com/sindresorhus/p-map/blob/main/index.js"
click node_iterator "https://github.com/sindresorhus/p-map/blob/main/index.js"
click node_stream_queue "https://github.com/sindresorhus/p-map/blob/main/index.js"
click node_skip_stop "https://github.com/sindresorhus/p-map/blob/main/index.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pmap,node_concurrent_engine toneBlue
class node_iterable,node_iterator,node_stream_queue toneAmber
class node_settled,node_keyed,node_keyed_settled,node_skip_stop,node_abort toneMint
class node_caller,node_input,node_mapper,node_results toneIndigo
```

## Components

### Concurrent Mapping

- [pMap](https://github.com/sindresorhus/p-map/blob/main/index.js): `index.js`
- [Concurrent Engine](https://github.com/sindresorhus/p-map/blob/main/index.js): `index.js`

### Streaming

- [pMapIterable](https://github.com/sindresorhus/p-map/blob/main/index.js): `index.js`
- [Iterator Pulling](https://github.com/sindresorhus/p-map/blob/main/index.js): `index.js`
- [Stream Buffer](https://github.com/sindresorhus/p-map/blob/main/index.js): `index.js`

### Result Policies

- [pMapSettled](https://github.com/sindresorhus/p-map/blob/main/index.js): `index.js`
- [Keyed Mapping](https://github.com/sindresorhus/p-map/blob/main/index.js): `index.js`
- [Settled Keyed](https://github.com/sindresorhus/p-map/blob/main/index.js): `index.js`
- [Skip / Stop Controls](https://github.com/sindresorhus/p-map/blob/main/index.js): `index.js`
- **Abort Signal**

### Other components

- **Library Caller**
- **Iterable Input**
- **Mapper Function**
- **Mapped Results**

## Connections

- Library Caller → pMap: invokes (evidence: `readme.md`)
- Library Caller → pMapSettled: invokes (evidence: `readme.md`)
- Library Caller → Keyed Mapping: invokes (evidence: `readme.md`)
- Library Caller → Settled Keyed: invokes (evidence: `readme.md`)
- Library Caller → pMapIterable: invokes (evidence: `readme.md`)
- Iterable Input → pMap: supplies items (evidence: `readme.md`)
- Mapper Function → pMap: maps items (evidence: `readme.md`)
- pMap → Concurrent Engine: delegates (evidence: `index.js`)
- pMapSettled → Concurrent Engine: delegates (evidence: `index.js`)
- Keyed Mapping → Concurrent Engine: maps entries (evidence: `index.js`)
- Settled Keyed → Concurrent Engine: maps entries (evidence: `index.js`)
- Iterable Input → pMapIterable: supplies items (evidence: `readme.md`)
- Mapper Function → pMapIterable: maps items (evidence: `readme.md`)
- pMapIterable → Iterator Pulling: pulls from (evidence: `index.js`)
- Iterator Pulling → Stream Buffer: fills slots (evidence: `index.js`)
- Concurrent Engine → Mapper Function: calls concurrently (evidence: `index.js`)
- Concurrent Engine → Skip / Stop Controls: handles controls (evidence: `index.js`)
- pMap → Abort Signal: accepts signal (evidence: `readme.md`)
- pMapIterable → Stream Buffer: yields buffered (evidence: `index.js`)
- pMap → Mapped Results: returns promise (evidence: `readme.md`)
- pMapSettled → Mapped Results: returns settled (evidence: `readme.md`)
- Keyed Mapping → Mapped Results: returns keyed (evidence: `readme.md`)
- Settled Keyed → Mapped Results: returns settled keys (evidence: `readme.md`)
- pMapIterable → Mapped Results: streams values (evidence: `readme.md`)
