mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
feat: add support for using keyword on discord.js Client and WebSocketManager (#10063)
* feat: add support for `using` keyword on client * fix: use async dispose * feat: add support for web socket manager disposing * fix: use interface for client --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { REST } from '@discordjs/rest';
|
||||
import { range, type Awaitable } from '@discordjs/util';
|
||||
import { polyfillDispose } from '@discordjs/util';
|
||||
import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
|
||||
import {
|
||||
Routes,
|
||||
@@ -17,6 +18,9 @@ import type { IIdentifyThrottler } from '../throttling/IIdentifyThrottler.js';
|
||||
import { DefaultWebSocketManagerOptions, type CompressionMethod, type Encoding } from '../utils/constants.js';
|
||||
import type { WebSocketShardDestroyOptions, WebSocketShardEvents } from './WebSocketShard.js';
|
||||
|
||||
// We put this here because in index.ts WebSocketManager seems to be outputted before polyfillDispose() is called from tsup.
|
||||
polyfillDispose();
|
||||
|
||||
/**
|
||||
* Represents a range of shard ids
|
||||
*/
|
||||
@@ -199,7 +203,7 @@ export interface ManagerShardEventsMap {
|
||||
];
|
||||
}
|
||||
|
||||
export class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> {
|
||||
export class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> implements AsyncDisposable {
|
||||
/**
|
||||
* The options being used by this manager
|
||||
*/
|
||||
@@ -334,4 +338,8 @@ export class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> {
|
||||
public fetchStatus() {
|
||||
return this.strategy.fetchStatus();
|
||||
}
|
||||
|
||||
public async [Symbol.asyncDispose]() {
|
||||
await this.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user