From 065e31d0d40bc81a87ff09450388f803a197a8f0 Mon Sep 17 00:00:00 2001 From: Hamir Mahal Date: Tue, 16 Mar 2021 10:02:25 -0700 Subject: [PATCH] improve readability of article in chapter 8, async This mostly has readability improvements. There is one change, adding "(this is the same as (result => alert(result))" to a comment, that is solely there for clarification, to help out people learning about this for the first time. --- 1-js/11-async/08-async-await/article.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/1-js/11-async/08-async-await/article.md b/1-js/11-async/08-async-await/article.md index bde7c72e..de965d48 100644 --- a/1-js/11-async/08-async-await/article.md +++ b/1-js/11-async/08-async-await/article.md @@ -69,10 +69,10 @@ The function execution "pauses" at the line `(*)` and resumes when the promise s Let's emphasize: `await` literally suspends the function execution until the promise settles, and then resumes it with the promise result. That doesn't cost any CPU resources, because the JavaScript engine can do other jobs in the meantime: execute other scripts, handle events, etc. -It's just a more elegant syntax of getting the promise result than `promise.then`, easier to read and write. +It's just a more elegant syntax of getting the promise result than `promise.then`. And, it's easier to read and write. ````warn header="Can't use `await` in regular functions" -If we try to use `await` in non-async function, there would be a syntax error: +If we try to use `await` in a non-async function, there would be a syntax error: ```js run function f() { @@ -83,7 +83,7 @@ function f() { } ``` -We may get this error if we forget to put `async` before a function. As said, `await` only works inside an `async` function. +We may get this error if we forget to put `async` before a function. As stated earlier, `await` only works inside an `async` function. ```` Let's take the `showAvatar()` example from the chapter and rewrite it using `async/await`: @@ -186,7 +186,7 @@ class Waiter { new Waiter() .wait() - .then(alert); // 1 + .then(alert); // 1 (this is the same as (result => alert(result))) ``` The meaning is the same: it ensures that the returned value is a promise and enables `await`.