Skip to content

Instantly share code, notes, and snippets.

@YCF
Forked from mikaelkaron/module.js
Last active August 29, 2015 14:06
Show Gist options
  • Save YCF/9a05ff00c4478076f57e to your computer and use it in GitHub Desktop.
Save YCF/9a05ff00c4478076f57e 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