feat: @discordjs/ws (#8260)

Co-authored-by: Parbez <imranbarbhuiya.fsd@gmail.com>
This commit is contained in:
DD
2022-07-22 20:13:47 +03:00
committed by GitHub
parent 830c670c61
commit 748d7271c4
37 changed files with 3659 additions and 2612 deletions

View File

@@ -0,0 +1,20 @@
import type { ShardRange } from '../ws/WebSocketManager';
export type Awaitable<T> = T | Promise<T>;
/**
* Yields the numbers in the given range as an array
* @example
* range({ start: 3, end: 5 }); // [3, 4, 5]
*/
export function range({ start, end }: ShardRange): number[] {
return Array.from({ length: end - start + 1 }, (_, i) => i + start);
}
/**
* Lazily evaluate a callback, storing its result
*/
export function lazy<T>(cb: () => T): () => T {
let defaultValue: T;
return () => (defaultValue ??= cb());
}