For instance consider the following control flow:
- The user clicks a button.
A popup should appear asking the user for some information. If he provides the info, step 2 should be called.
- An ajax call is done to the server, if the call succeeds, step 3 should be called
- The data from the ajax call should be processed and on success the final state should be invoked.
- The final success state.
How would you implement this? With callbacks? A nightmare...I'm not even going to implement it as the result would be totally unreadable, not to speak about maintainability of the code. Instead, with the jQuery Deferred object, the result might look as shown in this dummy jsfiddle example:
This reminds me a bit of the C# Task API with its