I started using Bluebird and I see that it changes the structure of the promise.
Everything is now with an underscore so it's private (?), so what indicates if the promise was fulfilled or failed or pending?
In contrast with the original structure:
Lets have 3 promises - 2 resolved and 1 in rejected state and mix them with one another promise - timeout that will be rejected after 1 second.
Promise.race
returns promise as soon one of the promises in the given array resolves or rejects.
const Promise = require("bluebird");
let p1 = Promise.resolve('first')
let p2 = new Promise((resolve) => {
setTimeout(resolve, 1e8)
})
let p3 = Promise.resolve('third')
Promise.race([
Promise.all([p1, p2, p3]).then(() => console.log('ok')),
new Promise((resolve, reject) => setTimeout(reject, 1e3)) // rejected after 1000 ms
])
.catch(() => console.log(`Promise p2 is in pending state: ${p2.isPending()}`))
.catch()
will logs Promise p2 is in pending state: true