Skip to content

Commit

Permalink
refactor(cluster): make onMessage() method synchronous
Browse files Browse the repository at this point in the history
The fetchSockets() method of the parent class is synchronous, so the
onMessage() method does not need to be asynchronous.
  • Loading branch information
darrachequesne committed Feb 21, 2024
1 parent 1d8da64 commit 5dcd182
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions lib/cluster-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 5dcd182

Please sign in to comment.