Last active
October 11, 2015 12:07
-
-
Save jpillora/3856141 to your computer and use it in GitHub Desktop.
jQuery Deferred Serializing Parallelizing Extensions
This file contains hidden or 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
//each accepts an array of functions that return a promise | |
$.Deferred.serialize = function(fns) { | |
if(!$.isArray(fns) || fns.length === 0) | |
return $.Deferred().resolve().promise(); | |
var pipeline = fns[0](), c = 1, l = fns.length; | |
for(;c < l;c++) | |
pipeline = pipeline.pipe(fns[c]); | |
return pipeline; | |
} | |
$.Deferred.parallelize = function(fns) { | |
if(!$.isArray(fns) || fns.length === 0) | |
return $.Deferred().resolve().promise(); | |
return $.when.apply(this,_.map(fns, function(fn) { return fn(); })); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment