promises: Move Gate from `server.js` (to enable reuse)
parent
c8d45586c1
commit
78a67801f3
|
@ -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` +
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue