Select: Make compose-friendly by taking a known number of arguments.
This commit is contained in:
parent
d7355e17e1
commit
6ea2b8bafe
5 changed files with 24 additions and 22 deletions
|
@ -18,7 +18,7 @@ it(`doubleselect`, async function() {
|
|||
// different channels.
|
||||
const sender = async (n, c1, c2, c3, c4) => {
|
||||
for (let i = 0; i < n; i++) {
|
||||
await Channel.select(c1.push(i), c2.push(i), c3.push(i), c4.push(i));
|
||||
await Channel.select([c1.push(i), c2.push(i), c3.push(i), c4.push(i)]);
|
||||
}
|
||||
|
||||
c1.close();
|
||||
|
|
|
@ -24,11 +24,11 @@ it(`select`, async function() {
|
|||
let i = 0;
|
||||
|
||||
do {
|
||||
switch (await Channel.select(
|
||||
switch (await Channel.select([
|
||||
a.push(GetValue()),
|
||||
b.push(GetValue()),
|
||||
closed.shift()
|
||||
)) {
|
||||
])) {
|
||||
case a:
|
||||
i++;
|
||||
a = Channel();
|
||||
|
|
|
@ -89,10 +89,10 @@ describe(`Channel`, function() {
|
|||
await a.shift();
|
||||
})();
|
||||
|
||||
assert.equal(await Channel.select(a.shift(), b.shift()), b);
|
||||
assert.equal(await Channel.select([a.shift(), b.shift()]), b);
|
||||
assert.equal(b.value, 0);
|
||||
assert.equal(await a.shift(), 1);
|
||||
assert.equal(await Channel.select(a.push(0), b.shift()), a);
|
||||
assert.equal(await Channel.select([a.push(0), b.shift()]), a);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -102,7 +102,7 @@ describe(`Channel`, function() {
|
|||
const nonBlocking = Channel();
|
||||
nonBlocking.close();
|
||||
|
||||
switch (await Channel.select(a.shift(), b.push(0), nonBlocking.shift())) {
|
||||
switch (await Channel.select([a.shift(), b.push(0), nonBlocking.shift()])) {
|
||||
case a:
|
||||
assert(false);
|
||||
break;
|
||||
|
@ -119,9 +119,12 @@ describe(`Channel`, function() {
|
|||
|
||||
it(`cancel`, async function() {
|
||||
const channel = Channel();
|
||||
Channel.select(channel.push(`cancelled`)).cancel();
|
||||
Channel.select([channel.push(`cancelled`)]).cancel();
|
||||
const closed = Channel.of();
|
||||
assert.equal(await Channel.select(channel.shift(), closed.shift()), closed);
|
||||
assert.equal(
|
||||
await Channel.select([channel.shift(), closed.shift()]),
|
||||
closed
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -251,7 +254,7 @@ describe(`Channel object`, function() {
|
|||
const channel = Channel();
|
||||
|
||||
return assertRejects(async () => {
|
||||
await Channel.select(channel.push(undefined));
|
||||
await Channel.select([channel.push(undefined)]);
|
||||
}, new TypeError(`Can't push 'undefined' to channel, use close instead.`));
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue