简体   繁体   English

如何取消Meteor.setTimeout?

[英]How to cancel Meteor.setTimeout?

How to cancel a Meteor.setTimeout in the middle? 如何取消中间的Meteor.setTimeout

Meteor.setTimeout(() => {
    console.log("Start!");
}, 10000);

In this case, I want to use a button to cancel it in the middle of 10 seconds. 在这种情况下,我想使用按钮在10秒钟的中间将其取消。 Don't let it show "Start!". 不要让它显示“开始!”。

If there is no way to cancel, is there any alternative way? 如果没有取消的方法,是否还有其他选择? Thanks 谢谢

Meteor gives you a numeric handle to identify your timeout so you can store this to a variable 流星为您提供了一个数字句柄来标识您的超时,因此您可以将其存储到变量中

var myTimeOutHandle = Meteor.setTimeout(function(){console.log("clearTimeout never called")}, 10000);

and then call this inside your event on the button 然后在按钮上的事件内部调用它

Meteor.clearTimeout(myTimeOutHandle);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM