The coding scenario written below was supposed to have two 4-second delays. However, when the code is run, it executes immediately. It seems that there might be a lack of understanding on my part regarding some basic concept, or perhaps there's a hidden error I'm unable to identify.
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();
(apologies for the incorrect indenting here. The indentation issues seem to be inconsistent and outside my control.)