Message from JavaScript discussions
April 2017
— The MAIN difference is readFile vs readFileSync
But for effective prupouses this is the equivalent?
new Promise((resolve, reject) => {
process.nextTick(() => {
console.log("Then run");
resolve()
})
})
console.log("Running loop");
for(var i = 0; i < 100; i++) {
console.log("Blocking");
};
— No
— I really want to understand this
— 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)