Rewrite concat
.
This commit is contained in:
parent
44d833575b
commit
35df66ce79
1 changed files with 5 additions and 19 deletions
24
lib/index.js
24
lib/index.js
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue