Last active
August 29, 2015 14:02
-
-
Save EduceHealth/ac0e4b6b8143ea951a63 to your computer and use it in GitHub Desktop.
$q promises
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 q1 = $scope.q1 = $q.defer() | |
var q2 = $scope.q2 = $q.defer() | |
var p1 = $scope.q1.promise | |
var p2 = $scope.q2.promise | |
$q.all([ | |
p1.then(function(value){console.log('p1 resolved ', value); | |
return value;}), | |
p2.then(function(value){console.log('p2 resolved ', value); | |
return value;}) | |
]) | |
.then(function(values) { | |
console.log('all is finished') | |
console.log(values); | |
return values; | |
}); | |
setTimeout(function () { | |
$scope.$apply( function() { | |
console.log('resolving delayed promise: p1'); | |
q1.resolve({value : 1}); | |
}); | |
}, 500, this); | |
setTimeout(function () { | |
$scope.$apply( function() { | |
console.log('resolving delayed promise: p2'); | |
q2.resolve({value : 2}); | |
}); | |
}, 3000, this); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment