I'm new to Promise. This is my code
function heavyProcess(){
var ts = + new Date();
while((+ new Date() - 2000) < ts ){
//2 second delay to simulate lengthy process
}
console.log('after 2 seconds');
return Promise.resolve("Done");
}
console.log("START");
heavyProcess().then(function(resolve){
console.log(resolve);
});
console.log("END");
It's output is
START
after 2 seconds
END
Done
How can I make it this way? I don't want a call to a heavy process blocks the next code.
START
END
after 2 seconds
Done
I've been reading about Promise but I seem can't make this work.