Denoで待機処理するのん、どうするんかなと思って試してみた。
こんな感じ。
すごくシンプル。
import { delay } from "https://deno.land/std@0.161.0/async/mod.ts";
console.log(new Date());
await delay(1000);
console.log(new Date());
delay | /async/mod.ts | std@0.161.0 | Deno
Deno 標準ライブラリ async | Octo's blog
ちなみに、Nodeではこんな感じ。
import { setTimeout } from 'node:timers/promises'
await setTimeout(1000);
Node v.15から、setTimeout()はPromise返してくれるようになったらしい。
Timers | Node.js v19.0.0 Documentation
setTimeoutをawait/asyncで書く方法
ちなみに、ちなみに従来的なやり方はこんな感じ。
await new Promise((resolve) => setTimeout(resolve, 1000));