From 725023fe5883ebc67723948a98e7c06042216fc0 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 22 Dec 2020 01:01:37 -0500 Subject: [PATCH] server: Refactor `stop()` to avoid no-async-promise-executor lint error Also log when Etherpad has stopped. --- src/node/server.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/node/server.js b/src/node/server.js index ece5ed25b..38ffce22c 100755 --- a/src/node/server.js +++ b/src/node/server.js @@ -106,12 +106,15 @@ exports.stop = async () => { if (stopped) return; stopped = true; console.log('Stopping Etherpad...'); - await new Promise(async (resolve, reject) => { - const id = setTimeout(() => reject(new Error('Timed out waiting for shutdown tasks')), 3000); - await hooks.aCallAll('shutdown'); - clearTimeout(id); - resolve(); - }); + let timeout = null; + await Promise.race([ + hooks.aCallAll('shutdown'), + new Promise((resolve, reject) => { + timeout = setTimeout(() => reject(new Error('Timed out waiting for shutdown tasks')), 3000); + }), + ]); + clearTimeout(timeout); + console.log('Etherpad stopped'); }; exports.exit = async (err) => {