Home / Function/ sleepWithAbort() — typescript-sdk Function Reference

sleepWithAbort() — typescript-sdk Function Reference

Architecture documentation for the sleepWithAbort() function in async.ts from the typescript-sdk codebase.

Entity Profile

Dependency Diagram

graph TD
  0df83784_3dd1_6369_ad77_a87c189f8f77["sleepWithAbort()"]
  eacbc0fc_6067_7424_3b32_066d8839c732["pollUntilComplete()"]
  eacbc0fc_6067_7424_3b32_066d8839c732 -->|calls| 0df83784_3dd1_6369_ad77_a87c189f8f77
  style 0df83784_3dd1_6369_ad77_a87c189f8f77 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/async.ts lines 154–182

function sleepWithAbort(ms: number, signal?: AbortSignal): Promise<void> {
  return new Promise((resolve, reject) => {
    if (signal?.aborted) {
      const error = new Error('Polling aborted');
      error.name = 'AbortError';
      reject(error);
      return;
    }

    const timeout = setTimeout(() => {
      if (signal && onAbort) {
        signal.removeEventListener('abort', onAbort);
      }
      resolve();
    }, ms);

    let onAbort: (() => void) | undefined;
    if (signal) {
      onAbort = () => {
        clearTimeout(timeout);
        signal.removeEventListener('abort', onAbort!);
        const error = new Error('Polling aborted');
        error.name = 'AbortError';
        reject(error);
      };
      signal.addEventListener('abort', onAbort);
    }
  });
}

Domain

Subdomains

Frequently Asked Questions

What does sleepWithAbort() do?
sleepWithAbort() is a function in the typescript-sdk codebase.
What calls sleepWithAbort()?
sleepWithAbort() is called by 1 function(s): pollUntilComplete.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free