Message from JavaScript discussions

April 2017

— Not right away, but in next tick

— 

Promise.resolve().then(function(){console.log("I run right away");});
console.log("I run before promise");
VM131:2 I run before promise
VM131:1 I run right away

— Promise.resolve().then(function(){console.log("I run right away");}); console.log("I run first");

— Yep

— As long as your call stack continues, it will be blocked

— This is great example of the use case

Promise.resolve().then(function(){console.log("Then run");});
console.log("Running loop");
for(var i = 0; i < 100; i++) {
console.log("Blocking");
};

Message permanent page

— When the succeding call stack finishes the then method executes, I see

— I see it is because for that next tick the promise method switches context back to the main call stack flow. If you dont have something there in the next tick the method runs right away

Message permanent page

— Sadly though this is not affected by closures :p

— You know how to implement a blocking sleep(ms)?

— Yes

— (not that you would want to)