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
Copy file name to clipboardExpand all lines: 1-js/11-async/08-async-await/01-rewrite-async/solution.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
2
-
The notes are below the code:
2
+
Примітки наведено під кодом:
3
3
4
4
```js run
5
5
asyncfunctionloadJson(url) { // (1)
@@ -17,17 +17,17 @@ loadJson('no-such-user.json')
17
17
.catch(alert); // Error: 404 (4)
18
18
```
19
19
20
-
Notes:
20
+
Примітки:
21
21
22
-
1.The function `loadJson`becomes`async`.
23
-
2.All`.then`inside are replaced with`await`.
24
-
3.We can `return response.json()`instead of awaiting for it, like this:
22
+
1.Функція `loadJson`стає`async`-функцією.
23
+
2.Усі`.then`всередині замінюються на`await`.
24
+
3.Ми можемо зробити `return response.json()`замість того, щоб чекати його, наприклад:
25
25
26
26
```js
27
27
if (response.status==200) {
28
28
returnresponse.json(); // (3)
29
29
}
30
30
```
31
31
32
-
Then the outer code would have to`await`for that promise to resolve. In our case it doesn't matter.
33
-
4. The error thrown from `loadJson` is handled by `.catch`. We can't use `await loadJson(…)` there, because we're not in an `async` function.
32
+
Тоді зовнішній код повинен був би чекати`await`, поки цей проміс буде виконано. У нашому випадку це не має значення.
33
+
4.Помилка, викликана `loadJson`, обробляється `.catch`. Ми не можемо використовувати там `await loadJson(…)`, тому що ми не використовуємо`async`-функцію.
0 commit comments