Skip to content

Commit 0b1458c

Browse files
authored
Merge pull request #519 from kopijka/patch-3
Update solution.md
2 parents 5f39bd8 + cf09b6b commit 0b1458c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

5-network/01-fetch/01-fetch-users/solution.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
To fetch a user we need: `fetch('https://api.github.com/users/USERNAME')`.
2+
Щоб отримати інформацію про користувачів, нам потрібно викликати : `fetch('https://api.github.com/users/USERNAME')`.
33

4-
If the response has status `200`, call `.json()` to read the JS object.
4+
Якщо відповідь приходить із статусом `200`, то викликаємо метод `.json()`, щоб прочитати JS-об'єкт.
55

6-
Otherwise, if a `fetch` fails, or the response has non-200 status, we just return `null` in the resulting array.
6+
В іншому випадку, якщо `fetch` завершується помилкою, або код статусу у відповіді відмінний від 200, то просто повертаємо значення `null` у масиві результатів.
77

8-
So here's the code:
8+
Ось код:
99

1010
```js demo
1111
async function getUsers(names) {
@@ -33,8 +33,8 @@ async function getUsers(names) {
3333
}
3434
```
3535

36-
Please note: `.then` call is attached directly to `fetch`, so that when we have the response, it doesn't wait for other fetches, but starts to read `.json()` immediately.
36+
Потрібно звернути увагу на те, що виклик `.then` прикріплений до `fetch`, щоб коли відповідь отримана, то одразу починати зчитування даних за допомогою `.json()` не очікуючи завершення інших запитів.
3737

38-
If we used `await Promise.all(names.map(name => fetch(...)))`, and call `.json()` on the results, then it would wait for all fetches to respond. By adding `.json()` directly to each `fetch`, we ensure that individual fetches start reading data as JSON without waiting for each other.
38+
Якщо, було б використано `await Promise.all(names.map(name => fetch(...)))` та викликали б `.json()` на результатах запитів, то треба було б чекати поки закінчилися всі запити. Викликаючи `.json()` одразу після кожного `fetch`, ми добились того, що зчитування надісланих по кожному окремому запиту відбуваєся незалежно від інших запитів.
3939

40-
That's an example of how low-level Promise API can still be useful even if we mainly use `async/await`.
40+
Це приклад того, як відносно низько-рівневе Promise API може бути корисним, навіть якщо ми переважно використовуємо `async/await`.

0 commit comments

Comments
 (0)