Slide 13
Slide 13 text
Promises – SeXling it
• Promises can exist in three states: pending, fulfilled, and rejected.
• Pending is the default state. From there, a promise can be “se4led” into
either fulfillment or rejec9on.
• Promise.all(p1, p2, p3)
– SeXle with a single rejecHon reason as soon as one of its dependencies is rejected.
– SeXle with all fulfillment results as soon as all of its dependencies are fulfilled.
• Promise.race(p1, p2, p3)
– Promise.race() is similar to Promise.all, except the first promise to seXle will “win” the
race, and its value will be passed along to branches of the race.
– RejecHons will also finish the race, and the race promise will be rejected.