Skip to content

Commit 9cf3452

Browse files
committed
fix: add clean up of state on disconnect
1 parent 326a2c4 commit 9cf3452

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/connection/client.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export class OpenFeedClient implements IOpenFeedClient {
7777
this.loopResetSource.reject(e);
7878
}
7979
} finally {
80+
await this.listeners.onCleanup();
8081
await this.listeners.onDisconnected();
8182
this.loopResetSource.resolve();
8283
}
@@ -153,8 +154,10 @@ export class OpenFeedClient implements IOpenFeedClient {
153154

154155
if (e instanceof ConnectionDisposedError) {
155156
this.logger?.warn("Stopping the client because of disposal");
156-
// eslint-disable-next-line no-await-in-loop
157+
/* eslint-disable no-await-in-loop */
158+
await this.listeners.onCleanup();
157159
await this.listeners.onDisconnected();
160+
/* eslint-enable no-await-in-loop */
158161
this.cleanUp();
159162
break;
160163
}

src/connection/listeners.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ export class OpenFeedListeners {
1818

1919
constructor() {
2020
this.onMessage = this.addDetails;
21+
this.onCleanup = this.cleanUp;
2122
}
2223

24+
private cleanUp = () => {
25+
this.instrumentByMarketId.clear();
26+
};
27+
2328
private addDetails = (message: OpenfeedGatewayMessage) => {
2429
let def: InstrumentDefinition | undefined;
2530
let symbols: [string, string][] | undefined;
@@ -119,6 +124,7 @@ export class OpenFeedListeners {
119124
};
120125

121126
/* eslint-disable class-methods-use-this */
127+
public onCleanup: () => void | Promise<void> = () => {};
122128
public onConnected: (connection: IOpenFeedConnection) => void | Promise<void> = () => {};
123129
public onCredentialsRejected: () => void | Promise<void> = () => {};
124130
public onDisconnected: () => void | Promise<void> = () => {};

0 commit comments

Comments
 (0)