Jannik

Jannik Baranczyk

Back to home
2024-02-12

How to sleep in TypeScript

This is a handy one-liner for delaying code execution in TypeScript:

const sleep = (ms: number) => new Promise(resolve, setTimeout(resolve, ms))

Usage

async function doSomething() {
  sleep(1000)
  doSomethingElse()
}