---
name: "up.util.timer"
area: "API"
kind: "JavaScript function"
parent: "up.util module"
url: "https://unpoly.com/api/up.util.timer"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.util module](https://unpoly.com/api/up.util.md)</nav>

# up.util.timer(millis, callback)

Waits for the given number of milliseconds, then runs the given callback.

This function works like the built-in [`setTimeout()`](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout), except that the argument order is flipped for ergonomic reasons.

Instead of `up.util.timer(0, fn)` you can also use [`up.util.task(fn)`](https://unpoly.com/api/up.util.task.md).

<nav aria-label="Contents">

#### Contents

- [Example](#example)
- [Parameters](#parameters)
- [Return value](#return-value)

</nav>

## Example {#example}

```js
up.util.timer(3000, function() {
  console.log("Look, it's 3 seconds later!")
})
```

---

## Parameters {#parameters}

### millis {#millis}

(required)

The time interval to wait in milliseconds.

Type: number

### callback {#callback}

(required)

The function to call after waiting.

Type: Function()

---

## Return value {#return-value}

The ID of the scheduled timeout.

To unschedule the task, pass this ID to [`clearTimeout()`](https://developer.mozilla.org/en-US/docs/Web/API/clearTimeout).

Type: number

