Skip to content

Instantly share code, notes, and snippets.

@mikaelkaron
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikaelkaron/93eab99b0f25c538cf3d to your computer and use it in GitHub Desktop.
Save mikaelkaron/93eab99b0f25c538cf3d to your computer and use it in GitHub Desktop.
Async jquery multi ajax
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