
Product
Introducing Module Reachability: Focus on the Vulnerabilities That Matter
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
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
import pMapSeries from '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};
});
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.
FAQs
Map over promises serially
The npm package p-map-series receives a total of 1,520,377 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.
Product
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
Product
Socket is introducing a new way to organize repositories and apply repository-specific security policies.
Research
Security News
Socket researchers uncovered malicious npm and PyPI packages that steal crypto wallet credentials using Google Analytics and Telegram for exfiltration.