Consider the following code:
var qq=$q(function(resolve, reject) {
setTimeout(function() {
if (true) {
console.log(qq);
resolve('Hello!');
console.log(qq);
} else {
...
}
}, 5000);
});
console.log(qq);
There are three console.log
commands. The last one is executed first and it correctly outputs a promise object with status 0. I was waiting for the first console.log
inside setTimeout
to output a promise object with pending status (0), since it stands before resolve. However, both of console.log
commands inside setTimeout
output a resolved promise with status 1. Could someone explain that to me?