JSPM

timeout-abort-controller

3.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 69873
  • Score
    100M100P100Q178392F
  • License MIT

An AbortController that aborts after a specified timeout

Package Exports

  • timeout-abort-controller
  • timeout-abort-controller/index.js

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-abort-controller) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

timeout-abort-controller

Build Status dependencies Status JavaScript Style Guide

An AbortController that aborts after a specified timeout.

timeout-abort-controller uses retimer internally to help reduce the impact of having numerous timers running.

Install

npm install timeout-abort-controller

Usage

const { AbortController } = require('native-abort-controller')
const { TimeoutController } = require('timeout-abort-controller')
const anySignal = require('any-signal')

const userController = new AbortController()
// Aborts after 1 second
const timeoutController = new TimeoutController(1000)

const combinedSignal = anySignal([userController.signal, timeoutController.signal])
combinedSignal.addEventListener('abort', () => console.log('Abort!'))

// The user or the timeout can now abort the action
await performSomeAction({ signal: combinedSignal })
timeoutController.clear()

API

new TimeoutController(ms)

Creates an AbortController compliant TimeoutController.

Parameters

Name Type Description
ms number The time in milliseconds for when the TimeoutController should abort

timeoutController.clear()

Clears the internal timer.

timeoutController.abort()

Aborts the controller and clears the internal timeout.

timeoutController.reset()

Clears the timer and sets the internal timeout to occur after the ms timeout it was created with.

LICENSE

MIT © Jacob Heun