Created
October 11, 2013 12:31
-
-
Save cromwellryan/6933859 to your computer and use it in GitHub Desktop.
composable promises from args (ie requirejs dependencies)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Q = require('q'); | |
console.log(); | |
function hi() { | |
Q.promise( function() { | |
console.log("hi: " + Date()); | |
}); | |
} | |
function bye() { | |
console.log("bye: " + Date()); | |
} | |
function what() { | |
var deferred = Q.defer(); | |
function done() { | |
console.log("what?: " + Date()); | |
deferred.resolve(); | |
} | |
setTimeout( done, 2000 ); | |
return deferred.promise; | |
} | |
function doall() { | |
args(arguments).reduce( function(seq, next) { | |
return seq.then(next); | |
}, Q()).done(); | |
} | |
function args(a) { | |
var args = []; | |
for(var key in a) { | |
args.push( a[key] ); | |
} | |
console.log(args); | |
return args; | |
} | |
doall(hi,bye,what); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment