Skip to content

Instantly share code, notes, and snippets.

@chaffeqa
Created May 15, 2013 19:37
Show Gist options
  • Save chaffeqa/5586705 to your computer and use it in GitHub Desktop.
Save chaffeqa/5586705 to your computer and use it in GitHub Desktop.
simple module for chaining something
function test_this( blah ){
var deferred = jQuery.Deferred();
function build(){
var d = jQuery.Deferred();
console.log("build",blah)
setTimeout(function(){ d.resolve(); },1000)
return d.promise();
}
function show(){
var d = jQuery.Deferred();
console.log("show",blah)
setTimeout(function(){ d.resolve(); },1000)
return d.promise();
}
function animate(){
var d = jQuery.Deferred();
console.log("animate",blah)
setTimeout(function(){ d.resolve(); },1000)
return d.promise();
}
function hide(){
var d = jQuery.Deferred();
console.log("hide",blah)
setTimeout(function(){ d.resolve(); },1000)
return d.promise();
}
function destroy(){
var d = jQuery.Deferred();
console.log("destroy",blah)
setTimeout(function(){ d.resolve(); },1000)
return d.promise();
}
build().then(function(){
return animate().then(function(){
return hide().then(function(){
return destroy().then(function(){
console.log("DONE", blah);
return deferred.resolve('ha');
})
})
})
})
return deferred.promise();
}
var test_this( 'variable' );
test_this.then(function(v){
console.log("finished chain: ", v);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment