promises: Move Gate from server.js (to enable reuse)

This commit is contained in:
Richard Hansen 2022-01-02 17:32:32 -05:00
parent c8d45586c1
commit 78a67801f3
2 changed files with 13 additions and 8 deletions

View file

@ -54,3 +54,15 @@ exports.timesLimit = async (total, concurrency, promiseCreator) => {
}
await Promise.all(promises);
};
/**
* An ordinary Promise except the `resolve` executor function is exposed as a property.
*/
class Gate extends Promise {
constructor(executor = null) {
let res;
super((resolve, reject) => { res = resolve; if (executor != null) executor(resolve, reject); });
this.resolve = res;
}
}
exports.Gate = Gate;