Take a look at the angular code below:
// 1.
var value = 0;
// 2.
value = 1;
$http.get('some_url')
.then(function() {
// 3.
value = 2;
})
.catch(function(){})
// 4.
value = 3
// 5.
value = 4
// 6.
$http.get('some_url')
Assuming that after statement 4
, the $http
request is completed.
Will statement 5
be executed next or will it be statement 3
?
If statement 5
is executed next, does this imply that all subsequent statements will be executed before the thread becomes free?
If statement 3
is executed next, does this mean that the promise always interrupts the thread based on the order of calls?
What is the standard rule for execution order, and are there any exceptions for more complex scenarios like nested promises?