Skip to content

Commit 774c899

Browse files
committed
update
1 parent df70581 commit 774c899

File tree

7 files changed

+95
-95
lines changed

7 files changed

+95
-95
lines changed

1-js/11-async/08-async-await/01-rewrite-async/solution.md

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

2-
The notes are below the code:
2+
Les notes sont en dessous du code:
33

44
```js run
55
async function loadJson(url) { // (1)
@@ -19,15 +19,15 @@ loadJson('no-such-user.json')
1919

2020
Notes:
2121

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. La fonction `loadJson` devient `async`.
23+
2. Tous les `.then` intérieurs sont remplacés par `await`..
24+
3. Nous pouvons `return response.json()` au lieu de l'attendre, comme ceci:
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+
Ensuite, le code externe devra "attendre" la résolution de cette promesse. Dans notre cas, cela n'a pas d'importance.
33+
4. L'erreur émise par `loadJson` est gérée par `.catch`. Nous ne pouvons pas utiliser `await loadJson(...)` ici, car nous ne sommes pas dans une fonction `async`..

1-js/11-async/08-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+
# Réécriture avec async/await
33

4-
Rewrite this example code from the chapter <info:promise-chaining> using `async/await` instead of `.then/catch`:
4+
Réécrire cet exemple de code du chapitre <info:promise-chaining> en utilisant `async/await` au lieu de `.then/catch`:
55

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

1-js/11-async/08-async-await/02-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+
Il n'y a pas d'astuces ici. Remplacez simplement `.catch` par `try..catch` dans `demoGithubUser` et ajoutez `async/await` là où c'est nécessaire:
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+
// demander un nom d'utilisateur jusqu'à ce que github renvoie un utilisateur valide
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; // pas d'erreur, sortie de la boucle
3232
} catch(err) {
3333
if (err instanceof HttpError && err.response.status == 404) {
34-
// loop continues after the alert
34+
// la boucle continue après l'alerte
3535
alert("No such user, please reenter.");
3636
} else {
37-
// unknown error, rethrow
37+
// erreur inconnue, rejeter
3838
throw err;
3939
}
4040
}

1-js/11-async/08-async-await/02-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" with async/await
2+
# Réécriture de "rethrow" avec async/await
33

4-
Below you can find the "rethrow" example. Rewrite it using `async/await` instead of `.then/catch`.
4+
Vous trouverez ci-dessous l'exemple "rethrow". Réécrivez-le en utilisant `async/await` au lieu de `.then/catch`.
55

6-
And get rid of the recursion in favour of a loop in `demoGithubUser`: with `async/await` that becomes easy to do.
6+
Et débarrassez-vous de la récursion en faveur d'une boucle dans `demoGithubUser` : avec `async/await`, cela devient facile à faire.
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+
// demander un nom d'utilisateur jusqu'à ce que github renvoie un utilisateur valide
2929
function demoGithubUser() {
3030
let name = prompt("Enter a name?", "iliakan");
3131

1-js/11-async/08-async-await/03-async-from-regular/solution.md

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

2-
That's the case when knowing how it works inside is helpful.
2+
C'est le cas quand il est utile de savoir comment ça marche à l'intérieur.
33

4-
Just treat `async` call as promise and attach `.then` to it:
4+
Il suffit de traiter l'appel `async` comme une promesse et d'y attacher `.then`:
55
```js run
66
async function wait() {
77
await new Promise(resolve => setTimeout(resolve, 1000));
@@ -10,7 +10,7 @@ async function wait() {
1010
}
1111

1212
function f() {
13-
// shows 10 after 1 second
13+
// affiche 10 après 1 seconde
1414
*!*
1515
wait().then(result => alert(result));
1616
*/!*
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
# Call async from non-async
2+
# Appeler l'asynchrone à partir du non-asynchrone
33

4-
We have a "regular" function called `f`. How can you call the `async` function `wait()` and use its result inside of `f`?
4+
Nous avons une fonction "normale" appelée `f`. Comment pouvez-vous appeler la fonction `async` `wait()` et utiliser son résultat à l'intérieur de `f` ?
55

66
```js
77
async function wait() {
@@ -11,10 +11,10 @@ async function wait() {
1111
}
1212

1313
function f() {
14-
// ...what should you write here?
15-
// we need to call async wait() and wait to get 10
16-
// remember, we can't use "await"
14+
// ...que devez-vous écrire ici?
15+
// nous devons appeler async wait() et attendre pour obtenir 10
16+
// Souvenez-vous, on ne peut pas utiliser "await".
1717
}
1818
```
1919

20-
P.S. The task is technically very simple, but the question is quite common for developers new to async/await.
20+
P.S. La tâche est techniquement très simple, mais la question est assez courante pour les développeurs novices en matière d'async/await.

0 commit comments

Comments
 (0)