Skip to content

Instantly share code, notes, and snippets.

@pbojinov
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbojinov/7271241557539b6cd18f to your computer and use it in GitHub Desktop.
Save pbojinov/7271241557539b6cd18f to your computer and use it in GitHub Desktop.
array of deferred
var doStuff = doAsyncThings();
$.when.apply(null, doStuff).done(function() {
console.log('done with async stuff');
});
function doAsyncThings() {
var deferreds = [];
deferreds.push(function() {
jQuery.ajax({
url: '/path/to/file',
type: 'GET',
complete: function(xhr, textStatus) {
//called when complete
},
success: function(data, textStatus, xhr) {
//called when successful
},
error: function(xhr, textStatus, errorThrown) {
//called when there is an error
}
});
});
return deferreds;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment