You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 10, 2022. It is now read-only.
Although you're writing code that looks synchronous, ensure you don't miss the
202
+
opportunity to do things in parallel.
203
+
204
+
async function series() {
205
+
await wait(500);
206
+
await wait(500);
207
+
return "done!";
208
+
}
209
+
210
+
The above takes 1000ms to complete, whereas:
211
+
212
+
async function parallel() {
213
+
const wait1 = wait(500);
214
+
const wait2 = wait(500);
215
+
await wait1;
216
+
await wait2;
217
+
return "done!";
218
+
}
219
+
220
+
…the above takes 500ms to complete, because both waits happen at the same time.
221
+
Let's look at a practical example…
222
+
223
+
### Example: Outputting fetches in order
200
224
201
225
Say we wanted to fetch a series URLs and log them as soon as possible, in the
202
226
correct order.
@@ -312,6 +336,10 @@ code-bloat.
312
336
313
337
## Async all the things!
314
338
315
-
Once async functions land across all browsers, use them on every promise-returning function! Not only do they make your code tider, but it makes sure that function will *always* return a promise.
339
+
Once async functions land across all browsers, use them on every
340
+
promise-returning function! Not only do they make your code tider, but it makes
341
+
sure that function will *always* return a promise.
316
342
317
-
I got really excited about async functions [back in 2014](https://jakearchibald.com/2014/es7-async-functions/){: .external}, and it's great to see them land, for real, in browsers. Whoop!
343
+
I got really excited about async functions [back in
344
+
2014](https://jakearchibald.com/2014/es7-async-functions/){: .external}, and
345
+
it's great to see them land, for real, in browsers. Whoop!
0 commit comments