promises: Return a `Promise` from `Gate.then()`
It doesn't make sense to return a `Gate` from `Gate.then()`, and this eliminates the semantically confusing constructor parameter.pull/5347/head
parent
78a67801f3
commit
b72db7ebd6
|
@ -59,9 +59,13 @@ 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` executor function is exposed as a property.
|
||||||
*/
|
*/
|
||||||
class Gate extends Promise {
|
class Gate extends Promise {
|
||||||
constructor(executor = null) {
|
// Coax `.then()` into returning an ordinary Promise, not a Gate. See
|
||||||
|
// https://stackoverflow.com/a/65669070 for the rationale.
|
||||||
|
static get [Symbol.species]() { return Promise; }
|
||||||
|
|
||||||
|
constructor() {
|
||||||
let res;
|
let res;
|
||||||
super((resolve, reject) => { res = resolve; if (executor != null) executor(resolve, reject); });
|
super((resolve, reject) => res = resolve);
|
||||||
this.resolve = res;
|
this.resolve = res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue