---
# System prepended metadata

title: Timers
tags: [zeta-dom]

---

---
tags: zeta-dom
---

Zeta DOM » [Disposables](/XigonPlaT-eWEEbN1jMglw)

# Timers

### `setTimeout`

Equivalent to `window.setTimeout`.

```typescript
import { setTimeout } from "zeta-dom/util";

const dispose = setTimeout(() => { /* ... */ });

// somewhere else
// calling clearTimeout under the hook
dispose();
```

### `setInteval`

Equivalent to `window.setInteval`.

:::warning
It is recommand to use `setIntevalSafe` for async operation.
:::

```typescript
import { setInteval } from "zeta-dom/util";

const dispose = setInteval(() => { /* ... */ }, 1000);

// somewhere else
// calling clearInteval under the hook
dispose();
```

### `setIntevalSafe`

Like `window.setInteval`, but the next run is not scheduled until current operation completes.

```typescript
import { setIntevalSafe } from "zeta-dom/util";

const dispose = setIntevalSafe(() => { 
    return longOperationReturningPromise();
}, 1000);

// somewhere else
// calling clearTimeout under the hook
dispose();
```
