From fedc36a55ebba3fdaac267297954d79cfbdc8608 Mon Sep 17 00:00:00 2001 From: Mark Nelissen Date: Mon, 11 Mar 2024 17:02:45 +0100 Subject: [PATCH 1/3] correctly await async close on adapters --- lib/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 60ab00c4eb..6f7e4b2240 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -741,14 +741,14 @@ export class Server< * * @param [fn] optional, called as `fn([err])` on error OR all conns closed */ - public close(fn?: (err?: Error) => void): void { - this._nsps.forEach((nsp) => { + public async close(fn?: (err?: Error) => void): Promise { + await Promise.allSettled([...this._nsps.values()].map(async (nsp) => { nsp.sockets.forEach((socket) => { socket._onclose("server shutting down"); }); - nsp.adapter.close(); - }); + await nsp.adapter.close(); + })); this.engine.close(); From 5b5fa9728a8f8efceddc3d4b8d2c91f03b4b65b5 Mon Sep 17 00:00:00 2001 From: Mark Nelissen Date: Wed, 13 Mar 2024 12:09:19 +0100 Subject: [PATCH 2/3] update formatting --- lib/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 6f7e4b2240..6d0448fdd0 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -742,13 +742,15 @@ export class Server< * @param [fn] optional, called as `fn([err])` on error OR all conns closed */ public async close(fn?: (err?: Error) => void): Promise { - await Promise.allSettled([...this._nsps.values()].map(async (nsp) => { + await Promise.allSettled( + [...this._nsps.values()].map(async (nsp) => { nsp.sockets.forEach((socket) => { socket._onclose("server shutting down"); }); await nsp.adapter.close(); - })); + }) + ); this.engine.close(); From beee91ef45dc83296b73ce334e9a0af70455d739 Mon Sep 17 00:00:00 2001 From: Mark Nelissen Date: Wed, 13 Mar 2024 12:27:55 +0100 Subject: [PATCH 3/3] whitespace fix --- lib/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 6d0448fdd0..cbdbe12c66 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -744,11 +744,11 @@ export class Server< public async close(fn?: (err?: Error) => void): Promise { await Promise.allSettled( [...this._nsps.values()].map(async (nsp) => { - nsp.sockets.forEach((socket) => { - socket._onclose("server shutting down"); - }); + nsp.sockets.forEach((socket) => { + socket._onclose("server shutting down"); + }); - await nsp.adapter.close(); + await nsp.adapter.close(); }) );