
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
p-map-series
Advanced tools
The p-map-series npm package allows you to map over promises serially. It processes each promise one after another, ensuring that only one promise is running at a time. This is useful for tasks that need to be performed in sequence rather than in parallel.
Serial Processing
This feature allows you to process an array of promise-returning functions in series. Each task is executed one after another, ensuring that only one task is running at any given time.
const pMapSeries = require('p-map-series');
const tasks = [
() => Promise.resolve('Task 1'),
() => Promise.resolve('Task 2'),
() => Promise.resolve('Task 3')
];
pMapSeries(tasks).then(results => {
console.log(results); // ['Task 1', 'Task 2', 'Task 3']
});
Error Handling
This feature demonstrates how p-map-series handles errors. If any task in the series fails, the entire process stops, and the error is caught in the catch block.
const pMapSeries = require('p-map-series');
const tasks = [
() => Promise.resolve('Task 1'),
() => Promise.reject(new Error('Task 2 failed')),
() => Promise.resolve('Task 3')
];
pMapSeries(tasks).then(results => {
console.log(results);
}).catch(error => {
console.error(error); // Error: Task 2 failed
});
The p-series package allows you to run promise-returning & async functions in series. It is similar to p-map-series but focuses solely on running promises in sequence without the mapping functionality.
The promise-sequential package runs an array of promise-returning functions sequentially. It is similar to p-map-series but is designed to be lightweight and straightforward, focusing solely on sequential execution.
Map over promises serially
Useful as a side-effect mapper. Use p-map
if you don't need side-effects, as it's concurrent.
$ npm install p-map-series
const pMapSeries = require('p-map-series');
const keywords = [
getTopKeyword() //=> Promise
'rainbow',
'pony'
];
let scores = [];
const mapper = async keyword => {
const score = await fetchScore(keyword);
scores.push(score);
return {keyword, score};
});
(async () => {
console.log(await pMapSeries(keywords, mapper));
/*
[
{
keyword: 'unicorn',
score: 99
},
{
keyword: 'rainbow',
score: 70
},
{
keyword: 'pony',
score: 79
}
]
*/
})();
Returns a Promise
that is fulfilled when all promises in input
and ones returned from mapper
are fulfilled, or rejects if any of the promises reject. The fulfilled value is an Array
of the mapper
created promises fulfillment values.
Type: Iterable<Promise | unknown>
Mapped over serially in the mapper
function.
Type: Function
Expected to return a value. If it's a Promise
, it's awaited before continuing with the next iteration.
MIT © Sindre Sorhus
FAQs
Map over promises serially
The npm package p-map-series receives a total of 1,561,959 weekly downloads. As such, p-map-series popularity was classified as popular.
We found that p-map-series demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.