Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Promise.race

// Promise.race()
// when you only want the result from the first
// resolved promise
//
//See video Tutorial: https://youtu.be/1cFl7WQDYYo

let p1 = Promise.reject(111);

let p2 = Promise.resolve(222);

let p3 = new Promise((resolve, reject)=>{
    setTimeout(resolve, 1000, 333);
});

Promise.race([p3, p2, p1])
    .then((result)=>{
        console.log('winning:', result);
})
    .catch((result)=>{
        console.log('Failed:', result);
})
Source by gist.github.com #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
4+7 =