Add 'Channel.all'.

This commit is contained in:
David 2021-02-02 14:58:39 -06:00
parent fb598b0270
commit fd503a978c
3 changed files with 33 additions and 1 deletions

View file

@ -364,6 +364,26 @@ const Channel = function(length = 0) {
);
};
Channel.all = channels => {
const output = Channel();
(async () => {
for (;;) {
const values = await Promise.all(channels.map(Channel.shift));
if (values.every(value => value === undefined)) {
break;
} else {
await output.push(values);
}
}
await output.close();
})();
return output;
};
// Node.js stream.readable
const fromNodeStream = (channel, stream) => {
stream.on(`readable`, async () => {