Last active
August 29, 2015 14:06
-
-
Save mikaelkaron/93eab99b0f25c538cf3d to your computer and use it in GitHub Desktop.
Async jquery multi ajax
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
define([ "when/parallel", "jquery" ], function (parallel, $) { | |
var tasks = [ "url1", "url2", "url3" ].map(function (url) { | |
return function () { | |
return $.get(url); | |
}; | |
}); | |
parallel(tasks) | |
.then(function (results) { | |
return results.reduce(function (sum, result) { | |
return sum + result.property; | |
}, 0) / results.length; | |
}) | |
.tap(function (result) { | |
alert(result); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment