<button onclick="promiseRace([firstPromise, secondPromise, thirdPromise]).then(ok=>console.log(ok), err=>console.log(err));">See to console</button>
function promiseRace(promises) {
return new Promise((ok,err)=>{
for (let elem of promises) {
elem()
.then(i => {
return ok(i);
}, err=>console.info(err))
.catch(
e=>err(['ERROR!', e])
)
}
})
}
const firstPromise = ()=> new Promise((resolve) =>
setTimeout(() => resolve(300), 300)
);
const secondPromise =()=> new Promise((resolve) =>
setTimeout(() => resolve(200), 200)
);
const thirdPromise = ()=> new Promise((resolve) =>
setTimeout(() => resolve(100), 100)
);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.