Allow promises to be passed through a channel.

This commit is contained in:
David Braun 2018-03-28 13:35:11 -04:00
parent 965d14d82c
commit 57247c6d10
No known key found for this signature in database
GPG key ID: 87EC41ADF710B7E2
2 changed files with 36 additions and 2 deletions

View file

@ -453,3 +453,25 @@ describe(`Channel object`, function() {
});
});
});
it(`allows promises to be sent through a channel`, function() {
return new Promise(async (resolve, reject) => {
process.once(`unhandledRejection`, reject);
const channel = Channel.of(
Promise.resolve(`resolved`),
new Promise((resolve, reject) => {
setImmediate(reject, new Error(`rejected`));
})
);
assert.equal(await channel.shift(), `resolved`);
try {
await channel.shift();
} catch (exception) {
assert.equal(exception.message, `rejected`);
resolve();
}
});
});