Rewrite concat.

This commit is contained in:
David 2021-02-08 16:24:06 -06:00
parent 44d833575b
commit 35df66ce79

View file

@ -108,30 +108,16 @@ const Channel = function(length = 0) {
const readOnly = Object.freeze(
Object.assign(Object.create(prototype), {
concat: (...args) => {
concat: (first, ...rest) => {
const output = Channel();
(async () => {
await readOnly.forEach(output.push);
for (let index = 0; index < args.length; index++) {
const arg = args[index];
/* For some reason the following code works in Mocha but not in
Wallaby.js:
await (Channel.isChannel(arg)
? arg.forEach(output.push)
: output.push(arg));
If we use the 'if' statement below then Wallaby.js is happy.
*/
if (Channel.isChannel(arg)) {
await arg.forEach(output.push);
} else {
await output.push(arg);
}
if (Channel.isChannel(first)) {
await first.concat(...rest).forEach(output.push);
} else {
await output.push(first);
}
await output.close();