Skip to content

Commit

Permalink
refactor: mark session broken when error or close
Browse files Browse the repository at this point in the history
  • Loading branch information
hans00 committed Sep 20, 2023
1 parent caf5d89 commit 2d42884
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/simple-mq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,14 @@ export class SimpleMQBroker extends EventEmitter {
protected handleClient(client: Client) {
let id: string | undefined;
let session: MQClientSession | undefined;
client.on('error', (err) => {
this.emit('error', err);
});
client.on('close', () => {
const connectionBroken = () => {
if (id && session) {
delete this.clients[id!];
session!.alive = false;
}
});
};
client.on('error', connectionBroken);
client.on('close', connectionBroken);
client.on('disconnect', () => {
client.end();
this.emit('clientDisconnected', id);
Expand Down

0 comments on commit 2d42884

Please sign in to comment.