Simplify handling of promises as values.
This commit is contained in:
parent
cdfb4655b5
commit
58fe68f1c4
2 changed files with 8 additions and 16 deletions
13
lib/index.js
13
lib/index.js
|
@ -61,13 +61,8 @@ const Channel = function(length = 0) {
|
|||
} else if (shift.cancelled) {
|
||||
index.shift++;
|
||||
} else {
|
||||
if (`reason` in push) {
|
||||
shift.reject(push.reason);
|
||||
} else {
|
||||
lastValue = push.value;
|
||||
shift.resolve(lastValue);
|
||||
}
|
||||
|
||||
lastValue = push.value;
|
||||
shift.resolve(lastValue);
|
||||
buffered = Math.max(0, buffered - 1);
|
||||
index.push++;
|
||||
index.shift++;
|
||||
|
@ -323,9 +318,7 @@ const Channel = function(length = 0) {
|
|||
// If value is a promise that rejects, catch it in case there hasn't
|
||||
// been a matching shift yet in order to prevent an unhandledRejection
|
||||
// error. Reject it again when there's a shift.
|
||||
Promise.resolve(value).catch(reason => {
|
||||
order.reason = reason;
|
||||
});
|
||||
Promise.resolve(value).catch(() => {});
|
||||
|
||||
if (closed) {
|
||||
order.reject(new Error(`Can't push to closed channel.`));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue