Day 65, promises

I have learned how to use promises in the client project and I spent some time teaching our current team members on how to use it today.

Basically, you create a deferred object, and return it(*). The promise or the contract is that, in the future, when the object changes its state from pending to resolved / rejected, the object will call its corresponding methods such as: object.then().

* means that the actual returned object is a sealed version of the object, meaning the receiver can observe, but can’t change its state by calling: object.resolve() or object.reject().

From my teaching experience, I feel like nobody gets the concept the first time, but everyone loves it once he finds out what is going on. I can’t imagine a world without promises…

Advertisements
Standard