Open this example in the interactive library
Source code
import {
setTimeout as delay,
setImmediate as immediate,
} from "node:timers/promises";
console.log(
await (async () => {
const { setInterval } = await import("node:timers/promises");
for await (const tick of setInterval(1, "tick")) return tick;
})(),
);
Sample output
tick
