Map over promises concurrently fast
npm install fast-p-mapA tiny zero-dependency, super-fast, concurrency-limited replacement for Promise.all([...].map(fn)).
Think of it as Array.prototype.map() for values that might be Promises, but with an upper bound on how many tasks run
in parallel.
This is a modified version of the p-Map package that has had its
configurability reduced to improve performance.
``shell script`
npm install fast-p-map
`js
// my-script.mjs
import fastPMap from '@your-scope/fast-p-map';
const urls = [
'https://example.com/a.json',
'https://example.com/b.json',
// …
];
const data = await fastPMap(urls, async url => {
const res = await fetch(url);
return res.json();
}, / concurrency / 5);
console.log(data);
`
Only five fetch requests will be in flight at any given time, no matter how many URLs you have.
---
`textmate`
fastPMap
iterable: Iterable
mapper: (item: Awaited
concurrency?: number = 10
): Promise
Parameter | Type | Description
---------------|-----------------------------------|---------------------------------------------------------------------------------------------
iterable | Iterable | Source of values (can contain Promises). mapper
| (item, index) => R | Function that converts each value. May be sync or async. concurrency
| number | Max tasks in parallel. Default: 10. Use Infinity (or a very large number) to disable.
Returns a Promise that resolves to an array of the mapped results, preserving the original order.
---
If mapper throws or rejects, iteration stops and the returned Promise rejects with that error (similar toPromise.all).
`js`
try {
await fastPMap(items, async x => {
if (x === 'bad') throw new Error('Broken');
return await doSomething(x);
});
} catch (err) {
console.error('❌ Fast-P-Map failed:', err);
}
---
- p-all - Run promise-returning & async functions concurrently with optional
limited concurrency
- p-filter - Filter promises concurrently
- p-times - Run promise-returning & async functions a specific number of
times concurrently
- p-props - Like Promise.all() but for Map and Object`
- p-map-series - Map over promises serially
- More…
MIT © 2025 atagon Gmbh Fürth