map: Return a buffered channel if appropriate.
This commit is contained in:
parent
e8c27056de
commit
4a4a2db7ed
2 changed files with 10 additions and 7 deletions
|
@ -178,7 +178,8 @@ const Channel = function(length = 0) {
|
|||
},
|
||||
|
||||
map: (callbackfn, thisArg) => {
|
||||
const output = Channel();
|
||||
const output = Channel(length);
|
||||
|
||||
(async () => {
|
||||
await readOnly.forEach(value => {
|
||||
output.push(callbackfn.call(thisArg, value));
|
||||
|
|
|
@ -269,12 +269,14 @@ describe(`Channel object`, function() {
|
|||
});
|
||||
|
||||
it(`map`, async function() {
|
||||
assert.deepEqual(
|
||||
await Channel.of(`a`, `b`, `c`)
|
||||
.map(value => value.toUpperCase())
|
||||
.values(),
|
||||
[`A`, `B`, `C`]
|
||||
);
|
||||
const channel = Channel(3);
|
||||
await channel.push(`a`);
|
||||
await channel.push(`b`);
|
||||
await channel.push(`c`);
|
||||
await channel.close();
|
||||
const mapped = channel.map(value => value.toUpperCase());
|
||||
assert.equal(mapped.length, channel.length);
|
||||
assert.deepEqual(await mapped.values(), [`A`, `B`, `C`]);
|
||||
});
|
||||
|
||||
describe(`push`, function() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue