From f45e9e070c93ebbd83d488bdd775987a4d75c201 Mon Sep 17 00:00:00 2001 From: t7yang Date: Mon, 10 Jan 2022 08:38:08 +0800 Subject: fix yari h2m dry run errors --- .../web/javascript/reference/statements/async_function/index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'files/zh-tw/web/javascript/reference/statements/async_function') diff --git a/files/zh-tw/web/javascript/reference/statements/async_function/index.html b/files/zh-tw/web/javascript/reference/statements/async_function/index.html index 1111e54da6..7faf5dcfef 100644 --- a/files/zh-tw/web/javascript/reference/statements/async_function/index.html +++ b/files/zh-tw/web/javascript/reference/statements/async_function/index.html @@ -45,8 +45,8 @@ translation_of: Web/JavaScript/Reference/Statements/async_function

async 函式內部可以使用 {{jsxref("Operators/await", "await")}} 表達式,它會暫停此 async 函式的執行,並且等待傳遞至表達式的 Promise 的解析,解析完之後會回傳解析值,並繼續此 async 函式的執行。

-
-

async/await 函式的目的在於簡化同步操作 promise 的表現,以及對多個 Promise 物件執行某些操作。就像 Promise 類似於具結構性的回呼函式,同樣地,async/await 好比將 generator 與 promise 組合起來。

+
+

備註:async/await 函式的目的在於簡化同步操作 promise 的表現,以及對多個 Promise 物件執行某些操作。就像 Promise 類似於具結構性的回呼函式,同樣地,async/await 好比將 generator 與 promise 組合起來。

範例

@@ -84,8 +84,8 @@ add2(10).then(v => { }); -
-

不要誤解 Promise.allawait

+
+

警告:不要誤解 Promise.allawait

add1 裡,該執行為了第一個 await 而暫停了兩秒,接著為了第二個 await 又暫停了兩秒。在第一個計時器(timer)被觸發前,第二個計時器並不會被建立。而在 add2 裡,兩個計時器都被建立起來、也都執行 await 過了。這把它帶往了 resolve 所的 2 秒暫停、而不是 4 秒暫停。然而這兩個 await 呼叫都在連續運行,而非平行運行。await 並不是 Promise.all 的自動程式。如果你想讓兩個、甚至兩個以上的 await promises 同時執行(in parallel),你必須使用 Promise.all.

-- cgit v1.2.3-54-g00ecf