ChemPal Documentation - v1.18.0
    Preparing search index...

    Function fetchWithTimeout

    • Calls fetch with a timeout. The abort also covers reading the body, so a stalled response can't hang a caller; the rejection is a TimeoutError DOMException.

      Parameters

      • input: URL | RequestInfo

        The URL or request to fetch

      • init: RequestInit = {}

        Extra fetch options; any signal is replaced by the timeout signal

      • timeoutMs: number = chemicalInfo.sourceTimeoutMs

        Milliseconds before aborting. Defaults to chemicalInfo.sourceTimeoutMs.

      Returns Promise<Response>

      The response

      const response = await fetchWithTimeout("https://pubchem.ncbi.nlm.nih.gov/rest/pug/...");
      // Rejects with a TimeoutError after 8 s without a complete response
      export function fetchWithTimeout(
      input: RequestInfo | URL,
      init: RequestInit = {},
      timeoutMs: number = chemicalInfo.sourceTimeoutMs,
      ): Promise<Response> {
      return fetch(input, { ...init, signal: AbortSignal.timeout(timeoutMs) });
      }