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

pull/5347/head
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

@ -50,6 +50,7 @@ const express = require('./hooks/express');
const hooks = require('../static/js/pluginfw/hooks');
const pluginDefs = require('../static/js/pluginfw/plugin_defs');
const plugins = require('../static/js/pluginfw/plugins');
const {Gate} = require('./utils/promises');
const stats = require('./stats');
const logger = log4js.getLogger('server');
@ -67,14 +68,6 @@ const State = {
let state = State.INITIAL;
class Gate extends Promise {
constructor(executor = null) {
let res;
super((resolve, reject) => { res = resolve; if (executor != null) executor(resolve, reject); });
this.resolve = res;
}
}
const removeSignalListener = (signal, listener) => {
logger.debug(`Removing ${signal} listener because it might interfere with shutdown tasks. ` +
`Function code:\n${listener.toString()}\n` +

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;