diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2023-09-02 19:12:47 -0400 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2023-09-02 19:12:47 -0400 |
commit | e4450c8417624b71d779cb4f41692538f9165e10 (patch) | |
tree | b70826542223ecdf8a7a259f61b0a1abb8a217d8 /node_modules/@sapphire/async-queue/dist/index.d.ts | |
download | sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.tar.gz sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.tar.bz2 sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.zip |
first commit
Diffstat (limited to 'node_modules/@sapphire/async-queue/dist/index.d.ts')
-rw-r--r-- | node_modules/@sapphire/async-queue/dist/index.d.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/node_modules/@sapphire/async-queue/dist/index.d.ts b/node_modules/@sapphire/async-queue/dist/index.d.ts new file mode 100644 index 0000000..0ea062c --- /dev/null +++ b/node_modules/@sapphire/async-queue/dist/index.d.ts @@ -0,0 +1,55 @@ +/** + * The AsyncQueue class used to sequentialize burst requests + */ +declare class AsyncQueue { + /** + * The amount of entries in the queue, including the head. + * @seealso {@link queued} for the queued count. + */ + get remaining(): number; + /** + * The amount of queued entries. + * @seealso {@link remaining} for the count with the head. + */ + get queued(): number; + /** + * The promises array + */ + private promises; + /** + * Waits for last promise and queues a new one + * @example + * ```typescript + * const queue = new AsyncQueue(); + * async function request(url, options) { + * await queue.wait({ signal: options.signal }); + * try { + * const result = await fetch(url, options); + * // Do some operations with 'result' + * } finally { + * // Remove first entry from the queue and resolve for the next entry + * queue.shift(); + * } + * } + * + * request(someUrl1, someOptions1); // Will call fetch() immediately + * request(someUrl2, someOptions2); // Will call fetch() after the first finished + * request(someUrl3, someOptions3); // Will call fetch() after the second finished + * ``` + */ + wait(options?: Readonly<AsyncQueueWaitOptions>): Promise<void>; + /** + * Unlocks the head lock and transfers the next lock (if any) to the head. + */ + shift(): void; + /** + * Aborts all the pending promises. + * @note To avoid race conditions, this does **not** unlock the head lock. + */ + abortAll(): void; +} +interface AsyncQueueWaitOptions { + signal?: AbortSignal | undefined | null; +} + +export { AsyncQueue, AsyncQueueWaitOptions }; |