MCPcopy Index your code
hub / github.com/TeleBoxOrg/TeleBox_Plugins / withTimeout

Function withTimeout

quote/quote.ts:220–228  ·  view source on GitHub ↗

* Race a promise against a timeout. On timeout the returned promise REJECTS with * QuoteTimeoutError (so the caller's try/catch can report it) and the timer is * always cleared to avoid leaks. The underlying RPC is abandoned, not cancelled — * gramjs has no cancel — but it no longer blocks the co

(promise: Promise<T>, ms: number, label: string)

Source from the content-addressed store, hash-verified

218 * gramjs has no cancel — but it no longer blocks the command from completing.
219 */
220function withTimeout<T>(promise: Promise<T>, ms: number, label: string): Promise<T> {
221 let timer: NodeJS.Timeout;
222 const timeout = new Promise<never>((_, reject) => {
223 timer = setTimeout(() => reject(new QuoteTimeoutError(label, ms)), ms);
224 // Don't keep the event loop alive solely for this timer.
225 if (typeof timer.unref === "function") timer.unref();
226 });
227 return Promise.race([promise, timeout]).finally(() => clearTimeout(timer)) as Promise<T>;
228}
229
230type QuoteArgs = {
231 count: number;

Callers 4

collectMessagesFunction · 0.85
editProgressFunction · 0.85
handleQuoteMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected