# mapWithConcurrency

Canonical: https://docs.shumoku.dev/en/library/api/mapWithConcurrency
Language: en

@shumoku/core · 0.4.0 · function

# mapWithConcurrency

[Source](https://github.com/konoe-akitoshi/shumoku/blob/main/libs/@shumoku/core/src/plugin-kit/concurrency.ts#L15)

Run \`fn\` over \`items\` with at most \`limit\` calls in flight at once, preserving input order in the result array. Replaces the two failure modes the audit found: unbounded \`Promise.all\` fan-out (network-scan would open hundreds of SNMP sockets at once) and fully sequential \`await\`-in-a-loop polling (zabbix walked hosts one by one). A rejected \`fn\` rejects the whole call (like \`Promise.all\`); a caller wanting partial results should catch inside \`fn\`.

```
mapWithConcurrency(items: readonly T[], limit: number, fn: object): Promise<R[]>
```

## Parameters

| Parameter | Type | Description | Default |
| --- | --- | --- | --- |
| `items` | `readonly T[]` | No additional description. | `—` |
| `limit` | `number` | No additional description. | `—` |
| `fn` | `object` | No additional description. | `—` |

## Returns

```
Promise<R[]>
```

[`libs/@shumoku/core/src/plugin-kit/concurrency.ts:15`](https://github.com/konoe-akitoshi/shumoku/blob/main/libs/@shumoku/core/src/plugin-kit/concurrency.ts#L15)
