I'm trying to run away from pyramid of doom. Imagine the following function call series:
$.wait(1000).done(function() {
//Do something
$.wait(5000).done(function(){
//Do something else
$.wait(2200).done(function(){
//Do something else
});
});
});
Where the $.wait function is defined as:
$.wait = function (duration) {
return $.Deferred(function (dfd) {
setTimeout(dfd.resolve, duration);
});
};
The question is that how can I refactor the above code so that it becomes readable/maintainable?