Get to know MDN better
此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
Promise.race(iterable) 方法回傳一個 promise 物件,此 promise 物件會於 iterable 引數中任一個 promise 轉為 resolve 或 rejected 時立即轉變成 resolve 或 rejected,並且接收其成功值或失敗訊息。
一個 iterable 物件,像是 Array. 請參考可迭代協議。
當傳入的 iterable 中有 promise 被實現或拒絕時,立刻回傳被實現或拒絕的 Promise。
race 函式回傳一個與傳入的 iterable 之中第一個被解決(settled)的 promise 相同方式被解決(且以相同值)的 Promise。
以下例子演示了 Promise.race 的非同步性質:
一個空的 iterable 造成回傳的 promise 永久擱置:
若 iterable 中有一個或多個非 promise 值且/或一個已經被實現/解決的 promise,Promise.race 將以陣列中第一個這樣的值解決:
| ECMAScript® 2027 Language Specification # sec-promise.race |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年7月14日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.