Skip to content
forked from ricokahler/pool

like Promise.all but you can limit the concurrency

License

Notifications You must be signed in to change notification settings

cybernetics/pool

 
 

Repository files navigation

@ricokahler/pool · codecov github status checks bundlephobia

Pool is like Promise.all but you can specify how many concurrent tasks you want at once.

Well tested. | Zero dependencies and small size.

npm i @ricokahler/pool
import pool from '@ricokahler/pool';

async function blah() {
  const texts = await pool({
    collection: [1, 2, 3, 4, 5],
    maxConcurrency: 2, // only fetch two pages at a time
    task: async (n) => {
      const response = await fetch(`/go/download/something/${n}`);
      const text = await response.text();
      return text;
    },
  });

  console.log(texts); // an array of the 5 items downloaded
}

maxConcurrency is optional. If omitted it will default to just using Promise.all with no max concurrency.

About

like Promise.all but you can limit the concurrency

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 90.2%
  • JavaScript 9.8%