here is my code.and its blocking. first its wait for some time then output the result. is there any way to write it non blocking so that output be like expected output output : 499999999067109000 4950 45 tick tick tick tick ...
expected Output be something like this: tick tick 45 tick tick ... 4950 tick tick tick .... 499999999067109000 tick tick ...
setImmediate(function(){
myCalc(1000000000).then(console.log).catch(console.error);
});
setImmediate(function(){
myCalc(100).then(console.log).catch(console.error);
});
setImmediate(function(){
myCalc(10).then(console.log).catch(console.error);
});
setInterval(function(){
console.log("tick");
},100);
function myCalc(n){
return new Promise((resolve, reject)=>{
try{
sum =0;
for(let i=0;i<n;i++){
sum += i;
}
resolve(sum);
}catch(err){
reject(err);
}
});
}