timeout-abort-controller
Version:
An AbortController that aborts after a specified timeout
67 lines (41 loc) • 2.27 kB
Markdown
//travis-ci.com/jacobheun/timeout-abort-controller.svg?branch=master)](https://travis-ci.com/jacobheun/timeout-abort-controller) [](https://david-dm.org/jacobheun/timeout-abort-controller) [](https://standardjs.com)
> An AbortController that aborts after a specified timeout.
`timeout-abort-controller` uses [`retimer`](https://github.com/mcollina/retimer) internally to help reduce the impact of having numerous timers running.
```
npm install timeout-abort-controller
```
```js
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()
```
Creates an [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) compliant `TimeoutController`.
| Name | Type | Description |
|------|------|-------------|
| ms | number | The time in milliseconds for when the TimeoutController should abort |
Clears the internal timer.
Aborts the controller and clears the internal timeout.
Clears the timer and sets the internal timeout to occur after the `ms` timeout it was created with.
- [`abort-controller`](https://github.com/mysticatea/abort-controller)
- [`native-abort-controller`](https://github.com/achingbrain/native-abort-controller)
- [`any-signal`](https://github.com/jacobheun/any-signal) Combines an array of AbortSignals into a single signal.
[ ](LICENSE) © Jacob Heun
[![Build Status](https: