How do I make this JS function asynchronous?

后端 未结 4 920
时光说笑
时光说笑 2021-02-04 02:58
function takesTime(){

    for (var i = 0; i

        
4条回答
  •  情歌与酒
    2021-02-04 03:16

    for (var i = 0; i < someVeryLargeNumber; ++i) {
        setTimeout(function () {
            //do something synchronous
        }, 0);
    }
    

    Also see setZeroTimeout to gain a few milliseconds each loop, although the work people are doing there seems to be browser-based.

提交回复
热议问题