Promise.race()

ES6+

Returns a promise that fulfills or rejects as soon as one of the promises fulfills or rejects.

Syntax

Promise.race(iterable)

Parameters

iterable Iterable

An iterable of promises

Return Value

Promise

A Promise that settles with the first settled promise

Examples

JavaScript
const slow = new Promise(r => setTimeout(() => r('느림'), 500));
const fast = new Promise(r => setTimeout(() => r('빠름'), 100));

Promise.race([slow, fast])
  .then(value => console.log(value));
Output:
// '빠름'

Related Methods