aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/promise/allsettled/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/promise/allsettled/index.html')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/promise/allsettled/index.html73
1 files changed, 73 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/promise/allsettled/index.html b/files/zh-cn/web/javascript/reference/global_objects/promise/allsettled/index.html
new file mode 100644
index 0000000000..de674edc7f
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/promise/allsettled/index.html
@@ -0,0 +1,73 @@
+---
+title: Promise.allSettled()
+slug: Web/JavaScript/Reference/Global_Objects/Promise/allSettled
+tags:
+ - Promise
+ - Promise.allSettled
+ - promise.all
+translation_of: Web/JavaScript/Reference/Global_Objects/Promise/allSettled
+---
+<p>{{JSRef}}</p>
+
+<p>该<code><strong>Promise.allSettled()</strong></code>方法返回一个在所有给定的promise都已经<code>fulfilled</code>或<code>rejected</code>后的promise,并带有一个对象数组,每个对象表示对应的promise结果。</p>
+
+<p>当您有多个彼此不依赖的异步任务成功完成时,或者您总是想知道每个<code>promise</code>的结果时,通常使用它。</p>
+
+<p><font><font>相比之下,</font></font><code><a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise/all">Promise.all()</a></code><font><font> 更适合彼此相互依赖或者在其中任何一个<code>reject</code>时立即结束。</font></font></p>
+
+<div>{{EmbedInteractiveExample("pages/js/promise-allsettled.html")}}</div>
+
+<h2 id="句法">句法</h2>
+
+<pre class="notranslate"><em>Promise</em>.allSettled(<em>iterable</em>);</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>iterable</code></dt>
+ <dd>一个<a href="/zh-CN/docs/Web/JavaScript/Guide/iterable">可迭代的</a>对象,例如{{jsxref("Array")}},其中每个成员都是<code>Promise</code>。</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p>一旦所指定的 promises 集合中每一个 promise 已经完成,无论是成功的达成或被拒绝,<strong>未决议的</strong> {{jsxref("Promise")}}将被<strong>异步</strong>完成。那时,所返回的 promise 的处理器将传入一个数组作为输入,该数组包含原始 promises 集中每个 promise 的结果。</p>
+
+<p>对于每个结果对象,都有一个 <code>status</code> 字符串。如果它的值为 <code>fulfilled</code>,则结果对象上存在一个 <code>value</code> 。如果值为 <code>rejected</code>,则存在一个 <code>reason</code> 。value(或 reason )反映了每个 promise 决议(或拒绝)的值。</p>
+
+<h2 id="标准">标准</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规格</th>
+ <th scope="col">状态</th>
+ <th scope="col">评论</th>
+ </tr>
+ <tr>
+ <td><a href="https://tc39.es/proposal-promise-allSettled/"><code>Promise.allSettled()</code> (TC39第4阶段草案)</a></td>
+ <td>{{SPEC2("ESDraft")}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容">浏览器兼容</h2>
+
+<p>{{Compat("javascript.builtins.Promise.allSettled")}}</p>
+
+<h3 id="实现进度">实现进度</h3>
+
+<p>{{EmbedTest262ReportResultsTable("Promise.allSettled")}}</p>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li>
+<a href="https://wiki.developer.mozilla.org/zh-CN/docs/Archive/Add-ons/Techniques/Promises">Promises</a></li>
+ <li>
+<a href="https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises">Using promises</a></li>
+ <li>
+<a href="https://wiki.developer.mozilla.org/zh-CN/docs/Learn/JavaScript/Asynchronous/Promises">Graceful asynchronous programming with promises</a></li>
+ <li>{{jsxref("Promise")}}</li>
+ <li>{{jsxref("Promise.all()")}}</li>
+</ul>