let p = newPromise((resolve, reject) => { let a = 1 + 1; if (a == 2) { resolve('Success') } else { reject('Failed') } }) // Anything inside .then method is going to run after resolve // .then take a function as parameter p.then((message) => { console.log('.then'+message) }).catch((message) => { console.log('.catch'+message) // run if promise rejected })
Promise.all([ recordVideoOne, rocordVideoTwo, recordVideoThree ]).then((messages) = > { // messages is an array of all messages console.log(messages) })
// All the three functions are run at the SAME time
Promise.race
Promise.race will return the fastest function, which is a single message in this case
1 2 3 4 5 6 7
Promise.race([ recordVideoOne, recordVideoTwo, recordVideoThree ]).then((message) => { // Only get one return value console.log(message) })