diff --git a/lib/index.js b/lib/index.js index 5bf5968..aa5664f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -326,23 +326,31 @@ Channel.select = methodPromises => Object.assign( new Promise((resolve, reject) => { methodPromises.forEach(async promise => { - promise.prethen(() => { - // We've been given a heads-up that this method will complete first so - // cancel the other method calls. - methodPromises.forEach(other => { - if (other !== promise) { - other.cancel(); - } - }); - }); - try { - await promise; - } catch (exception) { - reject(exception); - } + promise.prethen(() => { + // We've been given a heads-up that this method will complete first + // so cancel the other method calls. + methodPromises.forEach(other => { + if (other !== promise) { + other.cancel(); + } + }); + }); - resolve(promise.channel); + try { + await promise; + } catch (exception) { + reject(exception); + } + + resolve(promise.channel); + } catch (exception) { + reject( + new TypeError( + `Channel.select accepts only Channel method promises.` + ) + ); + } }); }), { diff --git a/test/index.js b/test/index.js index be85c78..f3eb702 100644 --- a/test/index.js +++ b/test/index.js @@ -128,6 +128,12 @@ describe(`Channel`, function() { 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() {