I expect in following code setInterval
runs 100 times before setTimeout
.
var current = 0;
var timer = setInterval(function(){
process.stdout.write(current.toString() + '\n');
if(current === 1000) {
clearInterval(timer);
process.stdout.write('Done');
}
current += 10;
}, 10);
setTimeout(function(){
process.stdout.write('This is 1000.\n');
}, 1000);
But its the result:
860
870
880
This is 1000.
890
900
910
920
930
940
950
960
970
980
990
1000
Done
What I did not understand about setInterval
? I think last setInterval
and setTimeout
should run together at the end.