Skip to content

Instantly share code, notes, and snippets.

@joshuaebowling
Last active March 11, 2016 16:28
Show Gist options
  • Save joshuaebowling/eb173d9e6dbcba6cb259 to your computer and use it in GitHub Desktop.
Save joshuaebowling/eb173d9e6dbcba6cb259 to your computer and use it in GitHub Desktop.
Using Async.js for Ajax Flow Control
var records = [{data:'data1'}, {data:'data2'}];
async.eachSeries(records, function (record, cb) {
// this was inside an angular project, but use whatever ajax call you want here
$http.post('http://myurltopost', record).
success(function (data, status, headers, config) {
cb(null, data);
})
.error(function (data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
cb('error', null);
});
}
, function (e) {
resolve(response);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment