As I understand a promise is something that can resolve() or reject() but I was suprised to find out that code in the promise continues to execute after a resolve or reject is called.
I considered resolve or reject being an async-friendly version of exit or return , that would halt all immediate function execution.
Can someone explain the thought behind why the following example sometimes shows the console.log after a resolve call:
var call = function() {
return new Promise(function(resolve, reject) {
resolve();
console.log("Doing more stuff, should not be visible after a resolve!");
});
};
call().then(function() {
console.log("resolved");
});
resolve()
is not a JS control statement that magically would have the effect ofreturn
, it's just a function call, and yes, execution continues after it. – user663031