# abort-controller-timer

> An AbortController that aborts after a specified timeout

Latest version **1.0.20** (published 2023-12-10) · ISC license · 0 weekly downloads

## Install

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

## 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 | 1.0.20 |
| Published | 2023-12-10 |
| First published | 2020-06-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 31 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | bluelovers |
| Maintainers | bluelovers |
| Keywords | timeout, w3c, whatwg, event, events, abort, cancel, abortcontroller, abortsignal, controller, signal, shim |

## Links

- npm: https://www.npmjs.com/package/abort-controller-timer
- Repository: https://github.com/bluelovers/ws-http
- Homepage: https://github.com/bluelovers/ws-http/tree/master/packages/abort-controller-timer#readme
- Issues: https://github.com/bluelovers/ws-http/issues
- npm.io page: https://npm.io/package/abort-controller-timer

## Dependencies (3)

- [tslib](https://npm.io/package/tslib.md) ^2
- [abort-controller](https://npm.io/package/abort-controller.md) ^3.0.0
- [abort-controller-util](https://npm.io/package/abort-controller-util.md) ^1.0.11

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.0.20 (latest) — 2023-12-10
- 1.0.19 — 2022-06-01
- 1.0.18 — 2022-05-08
- 1.0.16 — 2021-08-16
- 1.0.15 — 2021-08-12
- 1.0.13 — 2021-07-30
- 1.0.12 — 2021-07-30
- 1.0.11 — 2021-07-19
- 1.0.10 — 2021-07-11
- 1.0.9 — 2021-07-08
- 1.0.8 — 2021-07-08
- 1.0.6 — 2020-06-16
- 1.0.5 — 2020-06-16
- 1.0.3 — 2020-06-16

## README

# README.md

    An AbortController that aborts after a specified timeout

## install

```bash
yarn add abort-controller-timer abort-controller
yarn-tool add abort-controller-timer abort-controller
yt add abort-controller-timer abort-controller
```

```typescript
import AbortControllerTimer from 'abort-controller-timer';

test(`base`, (done) =>
{
	expect.assertions(8);

	let start = Date.now();

	let timeout = 100;
	let actual = new AbortControllerTimer(timeout);

	actual.on('abort', () => {
		let d = Date.now() - start;
		console.dir(d);

		expect(d).toBeGreaterThanOrEqual(100);
		expect(d).toBeLessThanOrEqual(110);
	})

	setTimeout(() => {
		expect(actual.aborted).toBeFalsy();
		expect(actual.timer).toBeTruthy()
	}, 70);

	setTimeout(() => expect(actual.aborted).toBeTruthy(), 100);
	setTimeout(() => expect(actual.aborted).toBeTruthy(), 150);
	setTimeout(() =>
	{
		expect(actual.aborted).toBeTruthy();
		done();
	}, 200);

	expect(actual).toHaveProperty('ms', timeout);

});

test(`refresh`, (done) =>
{
	expect.assertions(12);

	let start = Date.now();

	let timeout = 100;
	let actual = new AbortControllerTimer(timeout);

	actual.on('abort', () => {
		let d = Date.now() - start;
		console.dir(d);

		expect(d).toBeGreaterThanOrEqual(170);
		expect(d).toBeLessThanOrEqual(180);
	})

	setTimeout(() => {
		expect(Date.now() - start).toBeGreaterThanOrEqual(70);
		expect(actual.aborted).toBeFalsy();
		expect(actual.refresh()).toBeTruthy()
	}, 70);

	setTimeout(() => {
		expect(Date.now() - start).toBeGreaterThanOrEqual(100);
		expect(actual.aborted).toBeFalsy()
	}, 100);
	setTimeout(() => {
		expect(Date.now() - start).toBeGreaterThanOrEqual(150);
		expect(actual.aborted).toBeFalsy()
	}, 150);
	setTimeout(() =>
	{
		expect(Date.now() - start).toBeGreaterThanOrEqual(200);
		expect(actual.aborted).toBeTruthy();
		done();
	}, 200);

	expect(actual).toHaveProperty('ms', timeout);

});
```

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