Skip to content

Commit b1cc4a2

Browse files
jasnellthomasgauvin
authored andcommitted
Complete the example (#24273)
1 parent a97d098 commit b1cc4a2

File tree

1 file changed

+20
-8
lines changed
  • src/content/docs/workers/runtime-apis/nodejs

1 file changed

+20
-8
lines changed

src/content/docs/workers/runtime-apis/nodejs/timers.mdx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,26 @@ and [`setImmediate`](https://nodejs.org/api/timers.html#setimmediatecallback-arg
1717
```ts
1818
import timers from "node:timers";
1919

20-
console.log("first");
21-
timers.setTimeout(() => {
22-
console.log("last");
23-
}, 10);
24-
25-
timers.setTimeout(() => {
26-
console.log("next");
27-
});
20+
export default {
21+
async fetch() {
22+
console.log("first");
23+
const { promise1, resolve1 } = Promise.withResolvers();
24+
const { promise2, resolve2 } = Promise.withResolvers();
25+
timers.setTimeout(() => {
26+
console.log("last");
27+
resolve1();
28+
}, 10);
29+
30+
timers.setTimeout(() => {
31+
console.log("next");
32+
resolve2();
33+
});
34+
35+
await Promise.all([promise1, promise2]);
36+
37+
return new Response("ok");
38+
}
39+
}
2840
```
2941
</TypeScriptExample>
3042

0 commit comments

Comments
 (0)