Message from JavaScript discussions

April 2017

— I was referring to just the plain jane js promises which differ a few ways

— 

Lmao, I tried this, and it blocked right away.

new Promise((resolve, reject) => {
while(true);
})
console.log('Then')
setTimeout(() => console.log('Time is out'), 100)

— Nothig showed up

— Yes, a promise is for deferred execution, it is supposed to yield to the next highest execution context

Message permanent page

— And your promise does nothing

— Yeah, it does nothing but I'm trying to understand where it is executed.

— Read about continuation monads

— 

new Promise(function (res, rej) {
console.log("I run right away");
res("I run after everything");
}).then(function (data) {
console.log(data);
});
console.log("I run after");

VM361:2 I run right away
VM361:7 I run after
VM361:5 I run after everything

Message permanent page

— So, it always block.

— And its better no to use Sync versions

— The promise is created, runs it's callback, then yields to next highest context. then is run after resolve is run but only after that next highest context is finished

Message permanent page

— There is not new Promise alternative pattern