Channel.select: Complain when given non-channel method promises.

This commit is contained in:
David Braun 2017-10-18 10:37:07 -04:00
parent b5c96177e4
commit a2746f6e68
2 changed files with 29 additions and 15 deletions

View file

@ -326,9 +326,10 @@ Channel.select = methodPromises =>
Object.assign( Object.assign(
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
methodPromises.forEach(async promise => { methodPromises.forEach(async promise => {
try {
promise.prethen(() => { promise.prethen(() => {
// We've been given a heads-up that this method will complete first so // We've been given a heads-up that this method will complete first
// cancel the other method calls. // so cancel the other method calls.
methodPromises.forEach(other => { methodPromises.forEach(other => {
if (other !== promise) { if (other !== promise) {
other.cancel(); other.cancel();
@ -343,6 +344,13 @@ Channel.select = methodPromises =>
} }
resolve(promise.channel); resolve(promise.channel);
} catch (exception) {
reject(
new TypeError(
`Channel.select accepts only Channel method promises.`
)
);
}
}); });
}), }),
{ {

View file

@ -128,6 +128,12 @@ describe(`Channel`, function() {
closed closed
); );
}); });
it(`complains when given non-channel method promises`, function() {
assertRejects(async () => {
await Channel.select([Promise.resolve()]);
}, new TypeError(`Channel.select accepts only Channel method promises.`));
});
}); });
describe(`functional interface`, async function() { describe(`functional interface`, async function() {