mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +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();
|
await this.ws.connect();
|
||||||
return this.token;
|
return this.token;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.destroy();
|
await this.destroy();
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,13 +242,13 @@ class Client extends BaseClient {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs out, terminates the connection to Discord, and destroys the client.
|
* Logs out, terminates the connection to Discord, and destroys the client.
|
||||||
* @returns {void}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
destroy() {
|
async destroy() {
|
||||||
super.destroy();
|
super.destroy();
|
||||||
|
|
||||||
this.sweepers.destroy();
|
this.sweepers.destroy();
|
||||||
this.ws.destroy();
|
await this.ws.destroy();
|
||||||
this.token = null;
|
this.token = null;
|
||||||
this.rest.setToken(null);
|
this.rest.setToken(null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -320,12 +320,12 @@ class WebSocketManager extends EventEmitter {
|
|||||||
* Destroys this manager and all its shards.
|
* Destroys this manager and all its shards.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
destroy() {
|
async destroy() {
|
||||||
if (this.destroyed) return;
|
if (this.destroyed) return;
|
||||||
// TODO: Make a util for getting a stack
|
// TODO: Make a util for getting a stack
|
||||||
this.debug(`Manager was destroyed. Called by:\n${new Error().stack}`);
|
this.debug(`Manager was destroyed. Called by:\n${new Error().stack}`);
|
||||||
this.destroyed = true;
|
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) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
} finally {
|
} finally {
|
||||||
client.destroy();
|
await client.destroy();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ process.send(123);
|
|||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
console.log('Ready', client.options.shards);
|
console.log('Ready', client.options.shards);
|
||||||
if (client.options.shards === 0) {
|
if (client.options.shards === 0) {
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
console.log('kek dying');
|
console.log('kek dying');
|
||||||
client.destroy();
|
await client.destroy();
|
||||||
}, 5_000);
|
}, 5_000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ client
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
} finally {
|
} finally {
|
||||||
client.destroy();
|
await client.destroy();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.login(token)
|
.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 users: UserManager;
|
||||||
public voice: ClientVoiceManager;
|
public voice: ClientVoiceManager;
|
||||||
public ws: WebSocketManager;
|
public ws: WebSocketManager;
|
||||||
public destroy(): void;
|
public destroy(): Promise<void>;
|
||||||
public fetchGuildPreview(guild: GuildResolvable): Promise<GuildPreview>;
|
public fetchGuildPreview(guild: GuildResolvable): Promise<GuildPreview>;
|
||||||
public fetchInvite(invite: InviteResolvable, options?: ClientFetchInviteOptions): Promise<Invite>;
|
public fetchInvite(invite: InviteResolvable, options?: ClientFetchInviteOptions): Promise<Invite>;
|
||||||
public fetchGuildTemplate(template: GuildTemplateResolvable): Promise<GuildTemplate>;
|
public fetchGuildTemplate(template: GuildTemplateResolvable): Promise<GuildTemplate>;
|
||||||
@@ -3329,7 +3329,7 @@ export class WebSocketManager extends EventEmitter {
|
|||||||
private debug(message: string, shardId?: number): void;
|
private debug(message: string, shardId?: number): void;
|
||||||
private connect(): Promise<void>;
|
private connect(): Promise<void>;
|
||||||
private broadcast(packet: unknown): void;
|
private broadcast(packet: unknown): void;
|
||||||
private destroy(): void;
|
private destroy(): Promise<void>;
|
||||||
private handlePacket(packet?: unknown, shard?: WebSocketShard): boolean;
|
private handlePacket(packet?: unknown, shard?: WebSocketShard): boolean;
|
||||||
private checkShardsReady(): void;
|
private checkShardsReady(): void;
|
||||||
private triggerClientReady(): void;
|
private triggerClientReady(): void;
|
||||||
|
|||||||
Reference in New Issue
Block a user