Created
January 19, 2017 11:02
-
-
Save code-atom/f6f3afe28e60eb74088c5e86d3b63596 to your computer and use it in GitHub Desktop.
Understand the nested promise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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