mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(WebSocketShard): handle initial connect being a resume (#9549)
* fix(WebSocketShard): handle initial connect being a resume * chore: remove leftover --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -128,10 +128,26 @@ export class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {
|
||||
}
|
||||
|
||||
public async connect() {
|
||||
const promise = this.initialConnectResolved ? Promise.resolve() : once(this, WebSocketShardEvents.Ready);
|
||||
const controller = new AbortController();
|
||||
let promise;
|
||||
|
||||
if (!this.initialConnectResolved) {
|
||||
// Sleep for the remaining time, but if the connection closes in the meantime, we shouldn't wait the remainder to avoid blocking the new conn
|
||||
promise = Promise.race([
|
||||
once(this, WebSocketShardEvents.Ready, { signal: controller.signal }),
|
||||
once(this, WebSocketShardEvents.Resumed, { signal: controller.signal }),
|
||||
]);
|
||||
}
|
||||
|
||||
void this.internalConnect();
|
||||
|
||||
await promise;
|
||||
try {
|
||||
await promise;
|
||||
} finally {
|
||||
// cleanup hanging listeners
|
||||
controller.abort();
|
||||
}
|
||||
|
||||
this.initialConnectResolved = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user