Skip to content

Instantly share code, notes, and snippets.

@juanpicado
Last active August 29, 2015 14:23
Show Gist options
  • Save juanpicado/0c007786bf0dbf7105fd to your computer and use it in GitHub Desktop.
Save juanpicado/0c007786bf0dbf7105fd to your computer and use it in GitHub Desktop.
Promise future and past
var foo = function(a){
var promise = new Promise();
asyncAjaxFunction(a).done(function(){
promise.resolve();
}).fail(function(){
promise.reject();
})
};
foo.then(function(){
// all ok - resolve
}, function(){
// wrong - reject
});
// using the code of above
Promise.when(foo(1), foo(2), foo(3)).then(function(){
// all ok - resolve
}, function(){
// wrong - reject
});
var foo = function(callback){
asyncAjaxFunction().done(function(){
callback(true);
}).fail(function(){
callback(false);
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment