Skip to content

Commit b706d1a

Browse files
committed
Translate tasks in 6-async/05-async-await
1 parent 9b53d2e commit b706d1a

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

6-async/05-async-await/01-rewrite-async-2/solution.md

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

2-
There are no tricks here. Just replace `.catch` with `try...catch` inside `demoGithubUser` and add `async/await` where needed:
2+
ここには細工はありません。単に `demoGithubUser` の中の `.catch` `try...catch` に置き換え、必要な場所に `async/await` を追加しています:
33

44
```js run
55
class HttpError extends Error {
@@ -19,7 +19,7 @@ async function loadJson(url) {
1919
}
2020
}
2121

22-
// Ask for a user name until github returns a valid user
22+
// gitub が有効なユーザを返すまでユーザ名を訪ねる
2323
async function demoGithubUser() {
2424

2525
let user;
@@ -28,13 +28,13 @@ async function demoGithubUser() {
2828

2929
try {
3030
user = await loadJson(`https://api.github.com/users/${name}`);
31-
break; // no error, exit loop
31+
break; // エラーがない場合、ループを抜ける
3232
} catch(err) {
3333
if (err instanceof HttpError && err.response.status == 404) {
34-
// loop continues after the alert
34+
// alert の後ループを続ける
3535
alert("No such user, please reenter.");
3636
} else {
37-
// unknown error, rethrow
37+
// 未知のエラー、再スロー
3838
throw err;
3939
}
4040
}

6-async/05-async-await/01-rewrite-async-2/task.md

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

2-
# Rewrite "rethrow" async/await
2+
# "再スロー" を書き直す async/await
33

4-
Below you can find the "rethrow" example from the chapter <info:promise-chaining>. Rewrite it using `async/await` instead of `.then/catch`.
4+
下にチャプター <info:promise-chaining> にある "再スロー" の例があります。`.then/catch` の代わりに `async/await` を使って書き直してください。
55

6-
And get rid of the recursion in favour of a loop in `demoGithubUser`: with `async/await` that becomes easy to do.
6+
また、`demoGithubUser` のループのために(`async/await` が簡単になるよう)再帰を取り除きます。
77

88
```js run
99
class HttpError extends Error {
@@ -25,7 +25,7 @@ function loadJson(url) {
2525
})
2626
}
2727

28-
// Ask for a user name until github returns a valid user
28+
// gitub が有効なユーザを返すまでユーザ名を訪ねる
2929
function demoGithubUser() {
3030
let name = prompt("Enter a name?", "iliakan");
3131

6-async/05-async-await/01-rewrite-async/solution.md

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

2-
The notes are below the code:
2+
補足はコードの下にあります:
33

44
```js run
55
async function loadJson(url) { // (1)
@@ -17,17 +17,17 @@ loadJson('no-such-user.json')
1717
.catch(alert); // Error: 404 (4)
1818
```
1919

20-
Notes:
20+
補足:
2121

22-
1. The function `loadUrl` 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. 関数 `loadUrl` `async` になります。
23+
2. すべての内側の `.then` `await` に置き換えられます。
24+
3. 次のように、await するのではなく、`response.json()` を返すこともできます。:
2525

2626
```js
2727
if (response.status == 200) {
2828
return response.json(); // (3)
2929
}
3030
```
3131

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+
そうすると、外側のコードはその promise を解決するために `await` する必要があります。
33+
4. `loadJson` からスローされたエラーは `.catch` で処理されます。そこでは `await loadJson(…)` を使うことができません。なぜなら `async` 関数の中ではないからです。

6-async/05-async-await/01-rewrite-async/task.md

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

2-
# Rewrite using async/await
2+
# async/await を使用して書き直す
33

4-
Rewrite the one of examples from the chapter <info:promise-chaining> using `async/await` instead of `.then/catch`:
4+
チャプター <info:promise-chaining> にある例の1つを `.then/catch` の代わりに `async/await` を使って書き直してください。:
55

66
```js run
77
function loadJson(url) {

0 commit comments

Comments
 (0)