Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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,674,591 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.