JavaScript

Async Sleep / Delay

admin by @admin ADMIN
4d ago
Apr 28, 2026
Public
0 0 up · 0 down Sign in to vote
Returns a Promise that resolves after a given number of milliseconds. Use with await to pause async functions without blocking the main thread. More readable than nested setTimeout callbacks and composable with other async utilities.
JavaScript
Raw
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

// Usage
async function run() {
  console.log('start');
  await sleep(1000);
  console.log('1 second later');
  await sleep(500);
  console.log('done');
}

run();
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.