All Each Documentation

Overview#

Installation#

To install the all-each package, run the following command:

npm install all-each

Usage#

To use all-each, you need to provide the following parameters:

  • limiter: The count of concurrency (number of promises to run in parallel).
  • arr: A list of items to iterate over.
  • callback: An asynchronous callback function that takes an item and its index, returning a Promise<void>.
  • getDelay: A function that provides dynamic delays for executing promises.

Example#

const allEach = require('all-each');
 
const items = [1, 2, 3, 4, 5];
 
const processItem = async (item, index) => {
    // Simulate async operation
    return new Promise(resolve => setTimeout(() => {
        console.log(`Processed item ${item} at index ${index}`);
        resolve();
    }, 1000));
};
 
const limiter = 2; // Run 2 promises in parallel
 
allEach(limiter, items, processItem)
    .then(() => console.log('All items processed'));

API Documentation#

Parameters#

  • limiter: number - The maximum number of concurrent promises.
  • arr: Array - The array of items to process.
  • callback: (item: any, idx: number) => Promise<void> - The asynchronous function to process each item.
  • getDelay: (item: any, idx: number) => number (optional) - A function to determine the delay before processing each item.

Deployment#

To deploy the project, follow these steps:

  1. Install dependencies:

    npm install
  2. Build the project:

    npm build

This project was created using bun init in bun v1.1.0. For more information about Bun, visit the Bun website.

Updated

Was this page helpful?