
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@moznion/limited-concurrent-workers
Advanced tools
A library that provides a limited number of concurrent workers
A library that provides a limited number of concurrent workers for JavaScript/Typescript.
In JavaScript, if it needs to run the async functions parallelly with a restriction of the number of concurrent workers, the code has to be a little idiomatic. This library provides some wrappers for that purpose by using the Generator, for easiness and simplicity.
function* generator(): IterableIterator<string> {
for (let i = 0; i < 100; i++) {
yield i.toString();
}
}
// do something by three workers for the [0..99] numbers that come from the `generator()`.
const result = await runConcurrent<string, number>(
3,
arg => (resolve, reject) => {
// do something
resolve(Number(arg));
},
generator,
);
// example of the `result`
// result[0]: [
// 0, 3, 6, 9, 12, 15, 18, 21, 24,
// 27, 30, 33, 36, 39, 42, 45, 48, 51,
// 54, 57, 60, 63, 66, 69, 72, 75, 78,
// 81, 84, 87, 90, 93, 96, 99
// ]
//
// result[1]: [
// 1, 4, 7, 10, 13, 16, 19, 22, 25,
// 28, 31, 34, 37, 40, 43, 46, 49, 52,
// 55, 58, 61, 64, 67, 70, 73, 76, 79,
// 82, 85, 88, 91, 94, 97
// ]
//
// result[2]: [
// 2, 5, 8, 11, 14, 17, 20, 23, 26,
// 29, 32, 35, 38, 41, 44, 47, 50, 53,
// 56, 59, 62, 65, 68, 71, 74, 77, 80,
// 83, 86, 89, 92, 95, 98
// ]
async function runConcurrent<T, R>(maxConcurrency: number, executorProvider: (arg: T) => (resolve: (value: R | PromiseLike<R>) => void, reject: (reason?: unknown) => void) => void, generatorFunction: () => IterableIterator<T>): Promise<Awaited<R[][]>>async function runConcurrentFlatten<T, R>(maxConcurrency: number, executorProvider: (arg: T) => (resolve: (value: R | PromiseLike<R>) => void, reject: (reason?: unknown) => void) => void, generatorFunction: () => IterableIterator<T>): Promise<Awaited<R[]>>async function runConcurrentSettled<T, R>(maxConcurrency: number, executorProvider: (arg: T) => (resolve: (value: R | PromiseLike<R>) => void, reject: (reason?: unknown) => void) => void, generatorFunction: () => IterableIterator<T>): Promise<PromiseSettledResult<R[]>[]>Please see also typedoc.
moznion (moznion@mail.moznion.net)
FAQs
A library that provides a limited number of concurrent workers
The npm package @moznion/limited-concurrent-workers receives a total of 2 weekly downloads. As such, @moznion/limited-concurrent-workers popularity was classified as not popular.
We found that @moznion/limited-concurrent-workers 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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.