javascript set interval run as separate thread?

前端 未结 3 710
野趣味
野趣味 2021-02-13 14:41

I want to use a timer as a fallback in case I end up in an infinite loop. It seems that set interval is the right way to do this. However, it\'s not working for me.

Fro

3条回答
  •  梦毁少年i
    2021-02-13 15:14

    Browser javascript runs in a single thread. So if you perform something that takes too long - it will freeze browser.

    See John Resig article for further details: http://ejohn.org/blog/how-javascript-timers-work/

    After you read that article you'll get that your setInterval callback queued to be run in 1000ms after now but only after the current code is finished. It cannot finish though, because of the infinite loop.

提交回复
热议问题