What is the intention behind clause 2.2.4 of Promise/A+ spec?

The reasoning is that when the callbacks are always asynchronous instead of possibly asynchronous, it gives more consistent and reliable api to use. Consider the following code

var pizza;
browseStackOverflow().then(function(){
    eatPizza(pizza);
});
pizza = yesterdaysLeftovers;

Now that snippet clearly assumes the onFulfilled will not be called right away and if that wasn’t the case we would soon have unused pizza lying around and we’d be left hungry. Although in this case the bug would be easy enough to fix, the order of execution is easier to follow and thus the api is easier to use when you can make some assumptions like this.

There is a closed issue on the Promises/A+ GitHub repo with discussion about this.

Leave a Comment