Promise.race

race — A new Promise for when one Promise is completed (resolved or rejected), whichever is completed first.

Description

Promise.race(iterable promises)

Parameters

Name Description Type Default Optional
promises An array of promises. iterable No

Return values

A new Promise that resovles when one promise in the input array are completed.

Changelog

Version Description
ES 6 Introduced.

Examples

Example #1 – Promise.race example
let mypromise1 = new Promise(resolve => { resolve('resolved promise 1! :)'); }); let mypromise2 = new Promise((resolve, reject) => { resolve('resolved promise 2! :)'); }); Promise.race([mypromise1, mypromise2]).then(result => { console.log(result); });
Example #2 – Promise.race example
let mypromise1 = new Promise(resolve => { setTimeout(() => { resolve('resolved promise 1! :)'); }, 1000); }); let mypromise2 = new Promise((resolve, reject) => { setTimeout(() => { resolve('resolved promise 2! :)'); }, 500); }); Promise.race([mypromise1, mypromise2]).then(result => { console.log(result); });

External references