
Security News
Federal Audit Finds NIST Wasted Funds With No Plan to Clear NVD Backlog
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.
@sesamecare-oss/async-pool
Advanced tools
A utility function for processing items from an (async) generator with a configurable concurrency limit.
@sesamecare-oss/async-pool is a TypeScript/JavaScript library that provides a utility function for processing items from an (async) generator with a configurable concurrency limit. It allows you to efficiently handle IO-bound tasks (like network requests, file operations, etc.) in parallel, while controlling how many tasks run simultaneously.
Promise.all.npm install @sesamecare-oss/async-pool
import { asyncPool } from '@sesamecare-oss/async-pool';
async function* generator() {
yield 1;
yield 2;
yield 3;
yield 4;
yield 5;
}
const results: number[] = [];
await asyncPool(2, generator(), async (item) => {
// Only 2 iterator functions run concurrently
await doSomethingAsync(item);
results.push(item);
});
const items = [1, 2, 3, 4, 5];
function* generator() {
for (const item of items) {
yield item;
}
}
await asyncPool(3, generator(), async (item) => {
// Processing up to 3 items in parallel
await doSomethingAsync(item);
});
asyncPool returns an array of all the resolved values from the iterator function, in the order items were yielded.
const items = [1, 2, 3, 4, 5];
const doubles = await asyncPool(2, items.values(), async (item) => {
return item * 2;
});
console.log(doubles); // [2, 4, 6, 8, 10]
If any iterator function throws (or rejects), asyncPool will reject with that error and stop processing new items.
try {
await asyncPool(2, [1, 2, 3][Symbol.iterator](), async (item) => {
if (item === 2) throw new Error('fail!');
return item;
});
} catch (err) {
console.error(err); // Error: fail!
}
async function asyncPool<T, R>(
concurrency: number,
iterable: Iterable<T> | AsyncIterable<T>,
iteratorFn: (item: T, index: number) => Promise<R> | R
): Promise<R[]>;
concurrency: Maximum number of concurrently running tasks.iterable: Any iterable or async iterable source.iteratorFn: Async/sync function to execute for each item.MIT
FAQs
A utility function for processing items from an (async) generator with a configurable concurrency limit.
We found that @sesamecare-oss/async-pool demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.

Research
/Security News
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.

Research
/Security News
The North Korean malware loader hides in a Packagist-listed package and its GitHub branch to fetch and execute remote code in a likely Contagious Interview-style lure.