iterama
Version:
Composable functional (async) iterable helpers
31 lines (25 loc) • 714 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.zipAsync = zipAsync;
function zipAsync(...iterables) {
return {
async *[Symbol.asyncIterator]() {
const iterators = iterables.map(i => i[Symbol.asyncIterator]());
try {
while (true) {
const values = await Promise.all(iterators.map(i => i.next()));
if (values.some(v => v.done)) {
break;
}
yield values.map(v => v.value);
}
} finally {
await Promise.all(iterators.map(i => {
var _i$return;
return (_i$return = i.return) === null || _i$return === void 0 ? void 0 : _i$return.call(i);
}));
}
}
};
}