diff options
author | t7yang <t7yang@gmail.com> | 2022-01-10 08:38:08 +0800 |
---|---|---|
committer | Irvin <irvinfly@gmail.com> | 2022-02-16 02:35:54 +0800 |
commit | f45e9e070c93ebbd83d488bdd775987a4d75c201 (patch) | |
tree | aacef5edaf768a188cadc46860f5b6aaa74f39ef /files/zh-tw/web/javascript/reference/statements/async_function | |
parent | 8ccfa93045a6c119303566370999f59a0aae3b25 (diff) | |
download | translated-content-f45e9e070c93ebbd83d488bdd775987a4d75c201.tar.gz translated-content-f45e9e070c93ebbd83d488bdd775987a4d75c201.tar.bz2 translated-content-f45e9e070c93ebbd83d488bdd775987a4d75c201.zip |
fix yari h2m dry run errors
Diffstat (limited to 'files/zh-tw/web/javascript/reference/statements/async_function')
-rw-r--r-- | files/zh-tw/web/javascript/reference/statements/async_function/index.html | 8 |
1 files changed, 4 insertions, 4 deletions
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 <p>async 函式內部可以使用 {{jsxref("Operators/await", "await")}} 表達式,它會暫停此 async 函式的執行,並且等待傳遞至表達式的 Promise 的解析,解析完之後會回傳解析值,並繼續此 async 函式的執行。</p> -<div class="note"> -<p><code>async/await</code> 函式的目的在於簡化同步操作 promise 的表現,以及對多個 <code>Promise</code> 物件執行某些操作。就像 <code>Promise 類似於具結構性的回呼函式,同樣地,async/await 好比將 generator 與 promise 組合起來。</code></p> +<div class="notecard note"> +<p><strong>備註:</strong><code>async/await</code> 函式的目的在於簡化同步操作 promise 的表現,以及對多個 <code>Promise</code> 物件執行某些操作。就像 <code>Promise 類似於具結構性的回呼函式,同樣地,async/await 好比將 generator 與 promise 組合起來。</code></p> </div> <h2 id="範例">範例</h2> @@ -84,8 +84,8 @@ add2(10).then(v => { }); </pre> -<div class="warning"> -<h4 id="不要誤解_Promise.all_的_await">不要誤解 <code>Promise.all</code> 的 <code>await</code></h4> +<div class="notecard warning"> +<p><strong>警告:</strong>不要誤解 <code>Promise.all</code> 的 <code>await</code></p> <p>在 <code>add1</code> 裡,該執行為了第一個 <code>await</code> 而暫停了兩秒,接著為了第二個 <code>await</code> 又暫停了兩秒。在第一個計時器(timer)被觸發前,第二個計時器並不會被建立。而在 <code>add2</code> 裡,兩個計時器都被建立起來、也都執行 <code>await</code> 過了。這把它帶往了 resolve 所的 2 秒暫停、而不是 4 秒暫停。然而這兩個 <code>await</code> 呼叫都在連續運行,而非平行運行。<code>await</code> <strong>並不是</strong> <code>Promise.all</code> 的自動程式。如果你想讓兩個、甚至兩個以上的 <code>await</code> promises 同時執行(in parallel),你必須使用 <code>Promise.all</code>.</p> </div> |