同时暂停javascript

simultaneous pause javascript

本文关键字:javascript 暂停      更新时间:2023-09-26

我想暂停,但同时仍运行其他代码。例如:

while (true) {
    unit++
    // wait 3 seconds
}
// do this at the same time
while (true) {
    something += 25
    // wait 5 seconds
}

这将使单位每三秒增加1,每五秒增加25。时间单位以毫秒为单位,因此除以1000可以得到以秒为单位的时间,反之亦然。

setInterval(function() { 
    unit++;
}, 3000);
setInterval(function() { 
    something += 25;
}, 5000);