Category: Avoiding the callback hell with Deferred

  • Conclusion

    In this lesson we introduced you to promises, a better pattern for dealing with asynchronous code. Promises enable you to avoid having to use nasty tricks to synchronize parallel asynchronous functions and the need to nest callbacks inside callbacks inside callbacks. We outlined the Promises/A and the Promises/A+ proposals and explained how they compare with…

  • Promisifying all the things

    The previous sections focused on the Deferred and Promise objects and their methods, but we’ve reserved another small surprise for you: the promise() method. The latter is different from the deferred.promise() method that you learned a few pages back. promise() allows you to transform a jQuery object into a Promise object, enabling you to add handlers using the methods discussed in this lesson. The syntax of this…

  • Using the Promise object

    In order to master Deferreds and Promises you have to understand when to use one and when the other. To help you understand this topic, let’s say that you want to implement a promise-based timeout function. You are the producer of the function. In this case, the consumer of your function doesn’t need to care about resolving or rejecting it. The consumer…

  • The Deferred methods

    In jQuery, a Deferred object is created by calling the $.Deferred() constructor. The syntax of this function is as follows. Method syntax: $.Deferred $.Deferred([beforeStart]) A constructor function that returns a chainable utility object with methods to register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function. It…

  • The Deferred and Promise objects

    The Deferred object was introduced in jQuery 1.5 as a chainable utility used to register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function. Since then, it has been subject to discussions, some criticisms, and a lot of changes along the way.[1] This object can be used…

  • Introduction to promises

    In real life, the one away from computers (yes, there is something more out there), we often talk about promises. You ask people to make you a promise or you’re asked by others to promise something. Intuitively, a promise is a commitment derived from a request you make to ask a person to perform a…

  • Avoiding the callback hell with Deferred

    This lesson covers For a long time, JavaScript developers have used callback functions to perform several tasks such as running operations after a given amount of time (using set-Timeout()), or at regular intervals (using setInterval()), or to react to a given event (click, keypress, load, and so on). We’ve discussed and employed callbacks extensively to perform asynchronous operations; for…