# timeout-refresh

> Efficiently refresh a timer

Latest version **2.0.1** (published 2022-03-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install timeout-refresh
pnpm add timeout-refresh
yarn add timeout-refresh
bun add timeout-refresh
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2022-03-11 |
| First published | 2018-08-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | Mathias Buus |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/timeout-refresh
- Repository: https://github.com/mafintosh/timeout-refresh
- Issues: https://github.com/mafintosh/timeout-refresh/issues
- npm.io page: https://npm.io/package/timeout-refresh

## Recent versions

- 2.0.1 (latest) — 2022-03-11
- 2.0.0 — 2022-03-02
- 1.0.3 — 2020-10-05
- 1.0.2 — 2020-02-21
- 1.0.1 — 2019-09-18
- 1.0.0 — 2018-08-22

## README

# timeout-refresh

Efficiently refresh a timer

```
npm install timeout-refresh
```

Uses `timeout.refresh` in Node.
In the browser a basic `clearTimeout + setTimeout` is used since no other method exists

## Usage

``` js
const Timeout = require('timeout-refresh')

const to = Timeout.once(100, function () {
  console.log('Timed out!')
})

const i = setInterval(function () {
  // refresh every 50ms
  to.refresh()
}, 50)

setTimeout(function () {
  // cancel the refresh after 500ms
  clearInterval(i)
  setTimeout(function () {
    console.log('Should have timed out now')
  }, 200)
}, 500)
```

## API

#### `to = Timeout.once(ms, ontimeout, [context])`

Make a new refreshable timeout that fires once.

If you pass `context`, it will be set as `this` when calling `ontimeout`.

#### `to = Timeout.on(ms, ontimeout, [context])`

Make a new refreshable timeout that fires every `ms`.

If you pass `context`, it will be set as `this` when calling `ontimeout`.

#### `to.unref()`

Unref the timer.

#### `to.ref()`

Ref the timer.

#### `to.refresh()`

Refresh the timeout.

#### `to.destroy()`

Destroy the timeout.

## License

MIT

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