JSPM

timeout-signal

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1282232
  • Score
    100M100P100Q190182F
  • License MIT

Create an AbortSignal that aborts after a delay.

Package Exports

  • timeout-signal

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (timeout-signal) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

timeout-signal Travis CI Build Status

Create an AbortSignal that aborts after a delay.

NPM Badge

Install

npm install timeout-signal

Usage

const timeoutSignal = require("timeout-signal");
const fetch = require("cross-fetch");

try {
    const response = await fetch("https://www.google.com", { signal: timeoutSignal(5000) })
    // Handle response
} catch (error) {
    if (error.message === "The user aborted a request.") {
        // Handle abortion
    }
}

API

timeoutSignal(timeout)

timeout

Type: integer

The milliseconds to wait.

timeoutSignal.clear(signal)

Clear the timeout associated with a signal.

signal

Type: Return value from timeoutSignal()

The signal to clear the timeout for.

const timeoutSignal = require("timeout-signal");
const fetch = require("cross-fetch");

const signal = timeoutSignal(5000)

try {
    const response = await fetch("https://www.google.com", { signal })
    timeoutSignal.clear(signal)
    // Handle response
} catch (error) {
    if (error.message === "The user aborted a request.") {
        // Handle abortion
    }
}