JavaScript Promise.race() Explained

JavaScript Logo

Promise.race() – Returns the result of the first promise to settle (fulfilled or rejected).

๐Ÿ‘‰ Syntax

Promise.race([p1, p2]).then(fastest => {
  // first resolved value
});

๐Ÿงช Example

Promise.race([
  fetch('/slow'), fetch('/fast')
]).then(result => console.log(result));

Comments