Why clearInterval not stop immediately in heroku(为什么ClearInterval不在Heroku立即停止)
问题描述
我在Heroku托管了我的应用程序,我想在某种情况下停止setInterval函数。它在我本地的电脑上运行得很好,但在Heroku上却不行。在Heroku中,满足newEndX >= 800条件并调用clearInterval(intervalID)后,我的";updateLine()";函数仍被调用三次;
为什么仍然调用";updateLine()";,为什么调用了三次?Heroku与我们的本地计算机的工作方式是否不同?
intervalID = setInterval(function () {
if (newEndX < 800) {
updateLine();
}
if (newEndX >= 800) {
clearInterval(intervalID);
alert("You reached the end of the canvas. Please click 'reset' button to startover.")
console.log("reached the end of the canvas.")
console.log("The final startX is", newStartX);
console.log("The final endX is", newEndX);
}
}, 200);
更新:该问题可能是由于Heroku或我的浏览器中的一些未知问题造成的。这段代码在我同学的电脑和他的Heroku页面上运行良好。
推荐答案
setInterval是一个为请求形成队列Java脚本函数。即使发生错误,它也不会停止,直到它被清除。这是由于浏览器的内部计时器以及setInterval队列中的请求延迟造成的。
如果延迟增加,则setInterval不会停止并反复调用该函数。
这篇关于为什么ClearInterval不在Heroku立即停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么ClearInterval不在Heroku立即停止
基础教程推荐
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
