mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
fix(WebSocketManager): await WebSocket destroy (#9519)
fix(WebSocketManager): await ws destroy Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -226,7 +226,7 @@ class Client extends BaseClient {
|
||||
await this.ws.connect();
|
||||
return this.token;
|
||||
} catch (error) {
|
||||
this.destroy();
|
||||
await this.destroy();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -242,13 +242,13 @@ class Client extends BaseClient {
|
||||
|
||||
/**
|
||||
* Logs out, terminates the connection to Discord, and destroys the client.
|
||||
* @returns {void}
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
destroy() {
|
||||
async destroy() {
|
||||
super.destroy();
|
||||
|
||||
this.sweepers.destroy();
|
||||
this.ws.destroy();
|
||||
await this.ws.destroy();
|
||||
this.token = null;
|
||||
this.rest.setToken(null);
|
||||
}
|
||||
|
||||
@@ -320,12 +320,12 @@ class WebSocketManager extends EventEmitter {
|
||||
* Destroys this manager and all its shards.
|
||||
* @private
|
||||
*/
|
||||
destroy() {
|
||||
async destroy() {
|
||||
if (this.destroyed) return;
|
||||
// TODO: Make a util for getting a stack
|
||||
this.debug(`Manager was destroyed. Called by:\n${new Error().stack}`);
|
||||
this.destroyed = true;
|
||||
this._ws?.destroy({ code: CloseCodes.Normal });
|
||||
await this._ws?.destroy({ code: CloseCodes.Normal });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,7 @@ client.on('ready', async () => {
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
client.destroy();
|
||||
await client.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ process.send(123);
|
||||
client.on('ready', () => {
|
||||
console.log('Ready', client.options.shards);
|
||||
if (client.options.shards === 0) {
|
||||
setTimeout(() => {
|
||||
setTimeout(async () => {
|
||||
console.log('kek dying');
|
||||
client.destroy();
|
||||
await client.destroy();
|
||||
}, 5_000);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ client
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
client.destroy();
|
||||
await client.destroy();
|
||||
}
|
||||
})
|
||||
.login(token)
|
||||
|
||||
4
packages/discord.js/typings/index.d.ts
vendored
4
packages/discord.js/typings/index.d.ts
vendored
@@ -956,7 +956,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
||||
public users: UserManager;
|
||||
public voice: ClientVoiceManager;
|
||||
public ws: WebSocketManager;
|
||||
public destroy(): void;
|
||||
public destroy(): Promise<void>;
|
||||
public fetchGuildPreview(guild: GuildResolvable): Promise<GuildPreview>;
|
||||
public fetchInvite(invite: InviteResolvable, options?: ClientFetchInviteOptions): Promise<Invite>;
|
||||
public fetchGuildTemplate(template: GuildTemplateResolvable): Promise<GuildTemplate>;
|
||||
@@ -3329,7 +3329,7 @@ export class WebSocketManager extends EventEmitter {
|
||||
private debug(message: string, shardId?: number): void;
|
||||
private connect(): Promise<void>;
|
||||
private broadcast(packet: unknown): void;
|
||||
private destroy(): void;
|
||||
private destroy(): Promise<void>;
|
||||
private handlePacket(packet?: unknown, shard?: WebSocketShard): boolean;
|
||||
private checkShardsReady(): void;
|
||||
private triggerClientReady(): void;
|
||||
|
||||
Reference in New Issue
Block a user