Message from JavaScript discussions
April 2017
— This?
new Promise((resolve, reject) => {
setImmediate(() => {
console.log("Then run");
resolve()
})
})
console.log("Running loop");
for(var i = 0; i < 100; i++) {
console.log("Blocking");
};
new Promise(function (resolve, reject) {
resolve("Hello World");
}).then(function (data) {
console.log(data); // "Hello World!"
}).catch(function (exception) {
console.error(exception);
}).then(function (data) {
// This runs on both resolve & reject
});
— Ok, I'm back
— Are you using node promises?
— Yes
— Me?
— 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
— And your promise does nothing
— Yeah, it does nothing but I'm trying to understand where it is executed.