September 16
"Understanding JavaScript Promises" Nicholas C. Zakas
Memory training (promo)
“Each promise goes through a short lifecycle starting in the pending state, which indicates that promise hasn’t completed yet. A pending promise is considered unsettled. The promise in the previous example is in the pending state as soon as the fetch() function returns it. Once the promise completes, the promise is considered settled and enters one of two possible states (see Figure 1-1): 1. Fulfilled: The promise has completed successfully. 2. Rejected: The promise didn’t complete successfully due to either an error or some other cause.”“An internal [[PromiseState]] property is set to “pending”, “fulfilled”, or “rejected” to reflect the promise’s state. This property isn’t exposed on promise objects, so you can’t determine which state the promise is in programmatically. But you can take a specific action when a promise changes state by using the then() method.”“Promises also have a catch() method that behaves the same as then() when only a rejection handler is passed.”“To go along withthen()andcatch()there is alsofinally(). The callback passed to finally() (called a settlement handler) is called regardless of success or failure. Unlike the callbacks for then() and catch(), finally() callbacks do not receive any arguments because it isn’t clear whether the promise was fulfilled or rejected”
More notes at the link "Understanding JavaScript Promises"