Package Exports
- combine-async-iterators
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (combine-async-iterators) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Combine-async-iterators
Combine Multiple Asynchronous Iterators in one (not a sequence). It use Promise.race under the hood (the code idea is from Targos).
Requirements
- Node.js version 11 or higher
Getting Started
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-iteratorsUsage example
const combineAsyncIterators = require("combine-async-iterators");
async function* getValues(id) {
for (let count = 0; count < 5; count++) {
const ms = Math.ceil(Math.random() * 1000);
await new Promise((resolve) => setTimeout(resolve, ms));
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);API
function combineAsyncIterators(...iterators: AsyncIterableIterator<any>[]): AsyncIterableIterator<any>Licence
MIT