mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
promises: Move Gate from server.js
(to enable reuse)
This commit is contained in:
parent
c8d45586c1
commit
78a67801f3
2 changed files with 13 additions and 8 deletions
|
@ -50,6 +50,7 @@ const express = require('./hooks/express');
|
||||||
const hooks = require('../static/js/pluginfw/hooks');
|
const hooks = require('../static/js/pluginfw/hooks');
|
||||||
const pluginDefs = require('../static/js/pluginfw/plugin_defs');
|
const pluginDefs = require('../static/js/pluginfw/plugin_defs');
|
||||||
const plugins = require('../static/js/pluginfw/plugins');
|
const plugins = require('../static/js/pluginfw/plugins');
|
||||||
|
const {Gate} = require('./utils/promises');
|
||||||
const stats = require('./stats');
|
const stats = require('./stats');
|
||||||
|
|
||||||
const logger = log4js.getLogger('server');
|
const logger = log4js.getLogger('server');
|
||||||
|
@ -67,14 +68,6 @@ const State = {
|
||||||
|
|
||||||
let state = State.INITIAL;
|
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) => {
|
const removeSignalListener = (signal, listener) => {
|
||||||
logger.debug(`Removing ${signal} listener because it might interfere with shutdown tasks. ` +
|
logger.debug(`Removing ${signal} listener because it might interfere with shutdown tasks. ` +
|
||||||
`Function code:\n${listener.toString()}\n` +
|
`Function code:\n${listener.toString()}\n` +
|
||||||
|
|
|
@ -54,3 +54,15 @@ exports.timesLimit = async (total, concurrency, promiseCreator) => {
|
||||||
}
|
}
|
||||||
await Promise.all(promises);
|
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…
Add table
Add a link
Reference in a new issue