promises: Expose `reject` in `Gate`

pull/5347/head
Richard Hansen 2022-01-02 18:55:41 -05:00
parent b72db7ebd6
commit a115c475ad
1 changed files with 5 additions and 4 deletions

View File

@ -56,7 +56,8 @@ exports.timesLimit = async (total, concurrency, promiseCreator) => {
}; };
/** /**
* An ordinary Promise except the `resolve` executor function is exposed as a property. * An ordinary Promise except the `resolve` and `reject` executor functions are exposed as
* properties.
*/ */
class Gate extends Promise { class Gate extends Promise {
// Coax `.then()` into returning an ordinary Promise, not a Gate. See // Coax `.then()` into returning an ordinary Promise, not a Gate. See
@ -64,9 +65,9 @@ class Gate extends Promise {
static get [Symbol.species]() { return Promise; } static get [Symbol.species]() { return Promise; }
constructor() { constructor() {
let res; let props;
super((resolve, reject) => res = resolve); super((resolve, reject) => props = {resolve, reject});
this.resolve = res; Object.assign(this, props);
} }
} }
exports.Gate = Gate; exports.Gate = Gate;