Reputation: 1383
From CoffeeScript Accelerated JavaScript Development, chapter 6.6, question:
count = 10
h = setInterval (-> count--),100
do (->) until count is 0
clearInterval h
console.log 'Suprise!'
count won't be 0,I try to change 100 to 0,result is the same. which stack is the setInterval in? when will the callback function (-> count--) run?
Upvotes: 1
Views: 49
Reputation: 888243
Javascript is strictly single-threaded.
All asynchronous callbacks will only run after your code finishes running.
Your infinite loop never finishes running, so the setInterval
callback never runs.
Upvotes: 3