7
6

await sleep.js【async 1行JavaScript】コピペ可

Last updated at Posted at 2024-05-04
const sleep = s => new Promise(resolve => setTimeout(resolve, 1000 * s))

// 1秒待つ
await sleep(1)

// 5秒待つ
await sleep(5)

// 500ミリ秒待つ
await sleep(.5)
await new Promise(resolve => setTimeout(resolve, 3000)) // 3秒待つ

7
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6