
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
combine-async-iterators
Advanced tools
Combine Multiple Asynchronous Iterators in one (not a sequence)
Combine Multiple Asynchronous Iterators in one (not a sequence). It use Promise.race under the hood (the code idea is from Targos).
⚠️ This package was mainly built to work with native Asynchronous Generators (Iterators).
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
$ npm i combine-async-iterators
# or
$ yarn add combine-async-iterators
const { promisify } = require("util");
const combineAsyncIterators = require("combine-async-iterators");
const sleep = promisify(setTimeout);
async function* getValues(id) {
for (let count = 0; count < 5; count++) {
await sleep(Math.ceil(Math.random() * 1000));
yield `${id}_${count}`;
}
}
async function main() {
const asyncIterator = combineAsyncIterators({}, getValues("first"), getValues("second"));
for await (const value of asyncIterator) {
console.log(value);
}
}
main().catch(console.error);
Since 2.0.0 it is also possible to recover errors through a callback. By default the method is stopped when an error is thrown (the throwError
parameter allow to disable this behaviour).
function errorCallback(err) {
console.error("got you:", err);
}
const iteratorOptions = { errorCallback, throwError: false };
const asyncIterator = combineAsyncIterators(iteratorOptions, getValues("first"), getValues("second"));
for await (const value of asyncIterator) {
console.log(value);
}
declare function combineAsyncIterators(
...iterators: AsyncIterableIterator<any>[]
): AsyncIterableIterator<any>;
declare namespace combineAsyncIterators {
interface CombineOptions {
throwError?: boolean;
errorCallback?: (err: Error, index: number) => any;
}
}
declare function combineAsyncIterators(
options: combineAsyncIterators.CombineOptions,
...iterators: AsyncIterableIterator<any>[]
): AsyncIterableIterator<any>;
export = combineAsyncIterators;
MIT
FAQs
Combine Multiple Asynchronous Iterators in one (not a sequence)
The npm package combine-async-iterators receives a total of 754 weekly downloads. As such, combine-async-iterators popularity was classified as not popular.
We found that combine-async-iterators 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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.