
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
max-concurrency
Advanced tools
Sometimes you don't want to use Promise.all because sometimes you don't want all the promises you pass to it to be all in-flight at the same time. This package will allow you to limit how many promises are in-flight at the same time. The reason this API takes a list of promise providing functions is because if you passed it an array of promises, those promises would all already be in-flight.
import { Concurrency } from 'max-concurrency'
expect(await Concurrency.all({
promiseProviders: [
() => Promise.resolve(1),
() => Promise.resolve(2),
() => Promise.resolve(3),
() => Promise.resolve(4)
],
maxConcurrency: 3
})).toEqual([1, 2, 3, 4]);
This package also allows more control over error handling. Promise.all() will reject/throw when it encounters an error (ie. a rejected promise). This package will default to that same behavior but will also allow you to define an error mapper. This will map errors to "errored values" in the results and this allows for the rest of the promises to continue.
expect(await Concurrency.all({
promiseProviders: [
() => Promise.resolve(1),
() => Promise.reject(new Error("the error")),
() => Promise.resolve(3)
],
mapErrors: ({ message }) => ({ errorMessage: message })
})).toEqual([1, { errorMessage: "the error" }, 3]);
Just like Promise.all, this package will return the resolved values in the same order as the array of promise providers passed to it (not the order that the promises resolved in).
FAQs
Similar to Promise.all() but limits the number of promises in flight.
We found that max-concurrency 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
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.