Socket
Socket
Sign inDemoInstall

combine-async-iterators

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

39

index.js

@@ -21,19 +21,32 @@ "use strict";

/**
* @async
* @generator
* @function combineAsyncIterators
* @param {...AsyncIterableIterator<any>} iterators
*/
async function* combineAsyncIterators(...iterators) {
let open = iterators.length;
const promises = iterators.map(getNextAsyncIteratorValue);
try {
const promises = iterators.map(getNextAsyncIteratorValue);
let open = iterators.length;
do {
const { value, index } = await Promise.race(promises);
if (value.done) {
open--;
promises[index] = new Promise(() => null);
}
else {
yield value.value;
promises[index] = getNextAsyncIteratorValue(iterators[index], index);
}
} while (open > 0);
do {
const { value, index } = await Promise.race(promises);
if (value.done) {
open--;
promises[index] = new Promise(() => null);
}
else {
yield value.value;
promises[index] = getNextAsyncIteratorValue(iterators[index], index);
}
} while (open > 0);
}
catch (err) {
await Promise.all(iterators.map((it) => it.return()));
throw err;
}
}
module.exports = combineAsyncIterators;
{
"name": "combine-async-iterators",
"version": "1.0.0",
"version": "1.1.0",
"description": "Combine Multiple Asynchronous Iterators in one (not a sequence)",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc