Skip to content

Instantly share code, notes, and snippets.

@code-atom
Created January 19, 2017 11:02
Show Gist options
  • Save code-atom/f6f3afe28e60eb74088c5e86d3b63596 to your computer and use it in GitHub Desktop.
Save code-atom/f6f3afe28e60eb74088c5e86d3b63596 to your computer and use it in GitHub Desktop.
Understand the nested promise
var app = angular.module('app',[]);
app.run(function ($http, $q) {
getExample($q)
.then(function(value){
console.log(value);
});
})
function getExample($q) {
return resolvePromise($q).then(function(resultA) {
return resolvePromise($q).then(function(resultB) {
return resultA + resultB;
});
});
}
var resolvePromise = function($q){
var promise = $q.defer();
setTimeout(function(){
promise.resolve('at finish');
}, 1000);
return promise.promise;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment