# timeout-abort-controller

> An AbortController that aborts after a specified timeout

Latest version **3.0.0** (published 2022-01-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install timeout-abort-controller
pnpm add timeout-abort-controller
yarn add timeout-abort-controller
bun add timeout-abort-controller
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2022-01-12 |
| First published | 2019-12-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Jacob Heun |
| Maintainers | jacobheun |

## Links

- npm: https://www.npmjs.com/package/timeout-abort-controller
- Repository: https://github.com/jacobheun/timeout-abort-controller
- Homepage: https://github.com/jacobheun/timeout-abort-controller#readme
- Issues: https://github.com/jacobheun/timeout-abort-controller/issues
- npm.io page: https://npm.io/package/timeout-abort-controller

## Dependencies (1)

- [retimer](https://npm.io/package/retimer.md) ^3.0.0

## Recent versions

- 3.0.0 (latest) — 2022-01-12
- 2.0.0 — 2021-10-05
- 1.1.1 — 2020-06-09
- 1.1.0 — 2019-12-19
- 1.0.0 — 2019-12-10

## README

# timeout-abort-controller

[![Build Status](https://travis-ci.com/jacobheun/timeout-abort-controller.svg?branch=master)](https://travis-ci.com/jacobheun/timeout-abort-controller) [![dependencies Status](https://david-dm.org/jacobheun/timeout-abort-controller/status.svg)](https://david-dm.org/jacobheun/timeout-abort-controller) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](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.

## Install

```
npm install timeout-abort-controller
```

## Usage

```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()
```

## API

### `new TimeoutController(ms)`

Creates an [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/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.

## Related

- [`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

[MIT](LICENSE) © Jacob Heun

---
_Source: https://npm.io/package/timeout-abort-controller · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
