Promise.race()

noun

say it: “PROM-is RAYS” /ˈprɑmɪs reɪs/

A method that settles the same way as whichever promise in a list finishes first, whether that one worked or failed.

What does Promise.race() do in JavaScript?

Promise.race() — A method returning a Promise that settles when the first input settles.

const first = await Promise.race([request, timeout]);

In a sentence

  • “I used Promise.race() between the download and a five-second timer, so whichever came first decided what the page showed.”
  • “Promise.race() rejected because the timeout finished before the photo did.”

Level: Freelancer · More JavaScript terms at this level

Updated