I have a function
async function* values(input) {
...
}
this will yield some values depending on the input.
Now I have a set of inputs, let’s say [1,2,3,4,5]
, and I want to create another generator function that will use these inputs and call values
for each of them.
I want to yield back from the wrapping generator function whenever any of the values
call yields.
The function yields the generator sequentially:
function* generateValues() {
const inputs = [1,2,3,4,5];
const generators = inputs.map(input => values(input));
for (const generator of generators) {
yield await generator.next();
}
}
but I want to yield as soon as any of the generators yields, and keep yielding till all generators are drained.
I would like to replace the for loop above, with something like:
for await (const value of Generator.any(generators)) {
yield value;
}
i.e. I’m looking for something like Generator.any
which would be similar to Promise.any
but without throwing away the remaining generators.