Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

p-each-series

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-each-series

Iterate over promises serially

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.4M
decreased by-1.63%
Maintainers
1
Weekly downloads
 
Created

What is p-each-series?

The p-each-series package is a utility that allows you to iterate over a list of items and apply an asynchronous function to each item in series, meaning one after the other. It returns a Promise that resolves when all the iterations are completed. This is particularly useful when you need to perform async operations in a specific order.

What are p-each-series's main functionalities?

Iterating over an array in series

This code sample demonstrates how to use p-each-series to iterate over an array of items and log each item to the console one by one. After all items have been logged, it prints 'Done:' followed by the original array.

const pEachSeries = require('p-each-series');

const logItem = async item => {
  console.log(item);
  return item;
};

(async () => {
  const result = await pEachSeries(['a', 'b', 'c'], logItem);
  console.log('Done:', result);
})();

Handling asynchronous operations in series

This code sample shows how p-each-series can be used to perform asynchronous operations on each item in an array, with each operation being delayed by 1 second. It logs a message after each item is processed and finally logs that all items have been processed.

const pEachSeries = require('p-each-series');

const asyncOperation = item => new Promise(resolve => {
  setTimeout(() => {
    console.log(`Processed ${item}`);
    resolve(item);
  }, 1000);
});

(async () => {
  const result = await pEachSeries(['item1', 'item2', 'item3'], asyncOperation);
  console.log('All items have been processed:', result);
})();

Other packages similar to p-each-series

Keywords

FAQs

Package last updated on 09 Apr 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc