From 5dcd182736f94b9cbe3f4acb51621a59069f954d Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Wed, 21 Feb 2024 12:06:50 +0100 Subject: [PATCH] refactor(cluster): make onMessage() method synchronous The fetchSockets() method of the parent class is synchronous, so the onMessage() method does not need to be asynchronous. --- lib/cluster-adapter.ts | 44 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/cluster-adapter.ts b/lib/cluster-adapter.ts index 33a59a0..8858d0e 100644 --- a/lib/cluster-adapter.ts +++ b/lib/cluster-adapter.ts @@ -194,7 +194,7 @@ export abstract class ClusterAdapter extends Adapter { * @param offset * @protected */ - protected async onMessage(message: ClusterMessage, offset?: string) { + protected onMessage(message: ClusterMessage, offset?: string) { if (message.uid === this.uid) { return debug("[%s] ignore message from self", this.uid); } @@ -274,26 +274,26 @@ export abstract class ClusterAdapter extends Adapter { this.uid, message.data.opts ); - const localSockets = await super.fetchSockets( - decodeOptions(message.data.opts) - ); - - this.publishResponse(message.uid, { - type: MessageType.FETCH_SOCKETS_RESPONSE, - data: { - requestId: message.data.requestId, - sockets: localSockets.map((socket) => { - // remove sessionStore from handshake, as it may contain circular references - const { sessionStore, ...handshake } = socket.handshake; - return { - id: socket.id, - handshake, - rooms: [...socket.rooms], - data: socket.data, - }; - }), - }, - }); + super + .fetchSockets(decodeOptions(message.data.opts)) + .then((localSockets) => { + this.publishResponse(message.uid, { + type: MessageType.FETCH_SOCKETS_RESPONSE, + data: { + requestId: message.data.requestId, + sockets: localSockets.map((socket) => { + // remove sessionStore from handshake, as it may contain circular references + const { sessionStore, ...handshake } = socket.handshake; + return { + id: socket.id, + handshake, + rooms: [...socket.rooms], + data: socket.data, + }; + }), + }, + }); + }); break; } @@ -775,7 +775,7 @@ export abstract class ClusterAdapterWithHeartbeat extends ClusterAdapter { } } - override async onMessage(message: ClusterMessage, offset?: string) { + override onMessage(message: ClusterMessage, offset?: string) { if (message.uid === this.uid) { return debug("[%s] ignore message from self", this.uid); }