Skip to content

Commit

Permalink
🩹 fix(core): reconnect doesn't wait gateway to be disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
Helloyunho committed May 18, 2024
1 parent 449a214 commit 25516b0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/src/gateway/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class Gateway extends EventEmitter<GatewayEvents> {
);
const onopen = this.onopen.bind(this);
this.ws.onopen = () => {
this.ws.onopen = onopen;
onopen();
resolve();
};
Expand All @@ -99,6 +100,8 @@ export class Gateway extends EventEmitter<GatewayEvents> {

private onopen() {
this.connected = true;
this.reconnecting = false;
this.resume = false;
this.retryCount = 0;
this.emit("CONNECTED");
}
Expand Down Expand Up @@ -222,13 +225,13 @@ export class Gateway extends EventEmitter<GatewayEvents> {
this.connectionError = true;
}

reconnect(resume = false, code?: number) {
async reconnect(resume = false, code?: number) {
this.resume = resume;
this.reconnecting = true;
if (this.connected) {
this.disconnect(code, "reconnect");
await this.disconnect(code, "reconnect");
}
this.connect();
await this.connect();
}

heartbeat() {
Expand Down

0 comments on commit 25516b0

Please sign in to comment.