Skip to content

Commit 5dcd182

Browse files
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.
1 parent 1d8da64 commit 5dcd182

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

lib/cluster-adapter.ts

+22-22
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export abstract class ClusterAdapter extends Adapter {
194194
* @param offset
195195
* @protected
196196
*/
197-
protected async onMessage(message: ClusterMessage, offset?: string) {
197+
protected onMessage(message: ClusterMessage, offset?: string) {
198198
if (message.uid === this.uid) {
199199
return debug("[%s] ignore message from self", this.uid);
200200
}
@@ -274,26 +274,26 @@ export abstract class ClusterAdapter extends Adapter {
274274
this.uid,
275275
message.data.opts
276276
);
277-
const localSockets = await super.fetchSockets(
278-
decodeOptions(message.data.opts)
279-
);
280-
281-
this.publishResponse(message.uid, {
282-
type: MessageType.FETCH_SOCKETS_RESPONSE,
283-
data: {
284-
requestId: message.data.requestId,
285-
sockets: localSockets.map((socket) => {
286-
// remove sessionStore from handshake, as it may contain circular references
287-
const { sessionStore, ...handshake } = socket.handshake;
288-
return {
289-
id: socket.id,
290-
handshake,
291-
rooms: [...socket.rooms],
292-
data: socket.data,
293-
};
294-
}),
295-
},
296-
});
277+
super
278+
.fetchSockets(decodeOptions(message.data.opts))
279+
.then((localSockets) => {
280+
this.publishResponse(message.uid, {
281+
type: MessageType.FETCH_SOCKETS_RESPONSE,
282+
data: {
283+
requestId: message.data.requestId,
284+
sockets: localSockets.map((socket) => {
285+
// remove sessionStore from handshake, as it may contain circular references
286+
const { sessionStore, ...handshake } = socket.handshake;
287+
return {
288+
id: socket.id,
289+
handshake,
290+
rooms: [...socket.rooms],
291+
data: socket.data,
292+
};
293+
}),
294+
},
295+
});
296+
});
297297
break;
298298
}
299299

@@ -775,7 +775,7 @@ export abstract class ClusterAdapterWithHeartbeat extends ClusterAdapter {
775775
}
776776
}
777777

778-
override async onMessage(message: ClusterMessage, offset?: string) {
778+
override onMessage(message: ClusterMessage, offset?: string) {
779779
if (message.uid === this.uid) {
780780
return debug("[%s] ignore message from self", this.uid);
781781
}

0 commit comments

Comments
 (0)