In the code below I would expect two 4 second delays. But if you run the code you will see it executes instantly. Obviously I don't understand something very fundamental or I am a stupid error I can't see.
function calculatesomething(resolve) {
console.log("calculating");
setTimeout(results(resolve,3),4000);
}
var answer=0;
function results(resolve,n) {
console.log("got results");
answer=1;
resolve(answer+n);
}
function doingstuff() {
console.log("starting");
var promise1 = new Promise(function(resolve) {
setTimeout(calculatesomething(resolve),4000);
});
promise1.then(function(value) {
console.log("done: "+value);
});
console.log("regular execution");
}
doingstuff();
(sorry about the indenting here. I have no idea why its not respecting the tabs.)