Skip to content

Commit

Permalink
correctly await async close on adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Nelissen committed Mar 11, 2024
1 parent bf64870 commit fedc36a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/index.ts
Expand Up @@ -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<void> {
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();

Expand Down

0 comments on commit fedc36a

Please sign in to comment.