File tree Expand file tree Collapse file tree 1 file changed +20
-8
lines changed
src/content/docs/workers/runtime-apis/nodejs Expand file tree Collapse file tree 1 file changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -17,14 +17,26 @@ and [`setImmediate`](https://nodejs.org/api/timers.html#setimmediatecallback-arg
17
17
``` ts
18
18
import timers from " node:timers" ;
19
19
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
+ }
28
40
```
29
41
</TypeScriptExample >
30
42
You can’t perform that action at this time.
0 commit comments