# @repeaterjs/timers

> Async iterator timer functions

Latest version **0.3.3** (published 2019-11-10) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @repeaterjs/timers
pnpm add @repeaterjs/timers
yarn add @repeaterjs/timers
bun add @repeaterjs/timers
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.3.3 |
| Published | 2019-11-10 |
| First published | 2019-08-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 26.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 482 |
| Maintainers | brainkim |

## Links

- npm: https://www.npmjs.com/package/@repeaterjs/timers
- Repository: https://github.com/repeaterjs/repeater
- npm.io page: https://npm.io/package/@repeaterjs/timers

## Dependencies (1)

- [@repeaterjs/repeater](https://npm.io/package/@repeaterjs/repeater.md) ^3.0.0

## Recent versions

- 0.3.3 (latest) — 2019-11-10
- 0.3.2 — 2019-11-10
- 0.3.1 — 2019-08-29
- 0.3.0 — 2019-08-24
- 0.2.1 — 2019-08-22

## README

# @repeaterjs/timers
This package is experimental!

Cancelable timers, implemented with repeaters

For more information, visit [repeater.js.org](https://repeater.js.org).

```ts
function delay(wait: number): Repeater<number>;
```

`delay` returns a repeater which yields `Date.now()` `wait` milliseconds after `next` is called. Each call to `next` runs an independent timer. All outstanding timers can be canceled by calling `return`.

```ts
function timeout(wait: number): Repeater<undefined>;
```

`timeout` returns a repeater which rejects with a `TimeoutError` if the repeater does not receive another call to `next` or `return` after the specified `wait`. This behavior is useful when you want to place a fixed upper bound on how long each iteration of an async iterator can take with `Repeater.race`.

```js
import { Repeater } from "@repeaterjs/repeater";
import { timeout } from "@repeaterjs/timers";

const repeater = new Repeater(async (push) => {
  await push(1);
  await push(2);
  await new Promise((resolve) => setTimeout(resolve, 2000));
  await push(3);
});

try {
  (async () => {
    for await (const num of Repeater.race([repeater, timeout(1000)])) {
      console.log(num); // 1, 2
    }
  })();
} catch (err) {
  console.log(err); // TimeoutError: 1000 ms elapsed
}
```

```ts
function interval(wait: number, buffer?: RepeaterBuffer<number>): Repeater<number>;
```

`interval` returns a repeater which resolves with the current timestamp every `wait` milliseconds. The timer does not start until you call `next` on the returned iterator, and can be canceled by calling `return`.

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