# Wait for an amount of time

Return a promise that resolves after the given milliseconds.

Canonical: https://1loc.dev/misc/wait-for-an-amount-of-time/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Usage lines executed in Node.js 22 and headless Chromium; no external services
Updated: 2026-10-28

## Implementation

```javascript
function wait(milliseconds) { return new Promise(resolve => setTimeout(resolve, milliseconds)); }
```

## Usage

```javascript
const started = performance.now();
await wait(50);
// At least ~50 ms later (timers can fire a millisecond early):
performance.now() - started >= 45; // → true
```

Lines marked → were executed in Node.js 22 and in headless Chromium, and each result was compared with the value shown. Lines marked e.g. are illustrative.

## Limits

- setTimeout is a minimum delay, not a schedule: a busy event loop or a background tab can delay it much longer.
- Node.js ships the same: import { setTimeout as wait } from "node:timers/promises", which also accepts an AbortSignal.
- Typical use: await wait(retryAfterMs) before retrying a 429 or 503 response.

The function does not validate its arguments. Add checks where it receives untrusted input.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/wait-for-an-amount-of-time.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: furkankose
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Documented as a reference with executed usage lines. Original MDX retained as inert source evidence.
