Javascript: Async chains with jQuery.Deferred

Oscar Brito


Very useful utility to chain async events on javascript.

API: http://api.jquery.com/jQuery.Deferred/
Example:

function timeout(x) { 
       var dfd = jQuery.Deferred(); 
       setTimeout(function() { 
                 dfd.resolve(); 
       }, x); 
       return dfd.promise(); 

jQuery.when(timeout(800), timeout(500)).done(function() {});


The timeout function will call resolve and done function is invoked! It's more semantic and respect a common API (http://api.jquery.com/jQuery.Deferred/).




Visit www.divhide.com for more informations, contacts and news about Web Development.
See other blog posts at blog.divhide.com.



Divhide purpose is to follow the HTML5 movement and contribute with applications which prove the quality of technology.


Feel free to contact divhide.