Sleep / Delay Snippets
Sleep/delay code in 9 languages.
javascript
await new Promise(resolve => setTimeout(resolve, 1000));
Sleep / delay snippets across 9 languages. Useful for the moment you reach for "how do I sleep in X again?". JS doesn't have a built-in sleep - the await new Promise pattern is the standard.
About
Pick a language and millisecond value. Returns the sleep/delay snippet for JavaScript, TypeScript, Python (asyncio), Go, Rust, Swift, Kotlin, PHP, and Ruby.
How to use
- Set delay (ms).
- Pick a language.
FAQ
Does JavaScript have a built-in sleep?+
No. The standard pattern is await new Promise(r => setTimeout(r, ms)). Bun added Bun.sleep, Node has setTimeout/promises (timersPromises.setTimeout), but neither is universal.