Problems inherent to jQuery $.Deferred (jQuery 1.x/2.x)

Update: jQuery 3.0 has fixed the problems outlined below. It is truly Promises/A+ compliant. Yes, jQuery promises have serious and inherent problems. That said, since the article was written jQuery made significant efforts to be more Promises/Aplus complaint and they now have a .then method that chains. So even in jQuery returnsPromise().then(a).then(b) for promise returning … Read more

Issue in returning data retrieved from DB queries called in the loop

Let’s start with the general rule for using promises: Every function that does something asynchronous must return a promise Which functions are these in your case? It’s getPrayerInCat, the forEach callback, and Prayer.find. Hm, Prayer.find doesn’t return a promise, and it’s a library function so we cannot modify it. Rule 2 comes into play: Create … Read more

What is the explicit promise construction antipattern and how do I avoid it?

The deferred antipattern (now explicit-construction anti-pattern) coined by Esailija is a common anti-pattern people who are new to promises make, I’ve made it myself when I first used promises. The problem with the above code is that is fails to utilize the fact that promises chain. Promises can chain with .then and you can return … Read more