MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / abortableSleep

Function abortableSleep

src/utils/retry.ts:52–69  ·  view source on GitHub ↗

Sleep that rejects promptly if the signal aborts.

(ms: number, signal?: AbortSignal)

Source from the content-addressed store, hash-verified

50
51/** Sleep that rejects promptly if the signal aborts. */
52function abortableSleep(ms: number, signal?: AbortSignal): Promise<void> {
53 return new Promise((resolve, reject) => {
54 if (signal?.aborted) return reject(new Error('aborted'));
55 const t = setTimeout(() => {
56 cleanup();
57 resolve();
58 }, ms);
59 const onAbort = () => {
60 cleanup();
61 reject(new Error('aborted'));
62 };
63 const cleanup = () => {
64 clearTimeout(t);
65 signal?.removeEventListener('abort', onAbort);
66 };
67 signal?.addEventListener('abort', onAbort, { once: true });
68 });
69}
70
71/** Pull an HTTP-ish status code out of whatever error shape the SDK/fetch threw. */
72export function statusOf(err: any): number | undefined {

Callers 1

withRetryFunction · 0.85

Calls 1

cleanupFunction · 0.70

Tested by

no test coverage detected