mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16: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:
@@ -3,3 +3,4 @@ export * from './range.js';
|
||||
export * from './calculateShardId.js';
|
||||
export * from './runtime.js';
|
||||
export * from './userAgentAppendix.js';
|
||||
export * from './polyfillDispose.js';
|
||||
|
||||
14
packages/util/src/functions/polyfillDispose.ts
Normal file
14
packages/util/src/functions/polyfillDispose.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Polyfill for `Symbol.dispose` and `Symbol.asyncDispose` which is used as a part of
|
||||
* {@link https://github.com/tc39/proposal-explicit-resource-management}. Node versions below 18.x
|
||||
* don't have these symbols by default, so we need to polyfill them.
|
||||
*/
|
||||
export function polyfillDispose() {
|
||||
// Polyfill for `Symbol.dispose` and `Symbol.asyncDispose` if not available.
|
||||
// Taken from https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management
|
||||
|
||||
// @ts-expect-error This is a polyfill, so it's fine to write
|
||||
Symbol.dispose ??= Symbol('Symbol.dispose');
|
||||
// @ts-expect-error Same as above
|
||||
Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose');
|
||||
}
|
||||
Reference in New Issue
Block a user