Reputation: 49754
How to cancel a Meteor.setTimeout
in the middle?
Meteor.setTimeout(() => {
console.log("Start!");
}, 10000);
In this case, I want to use a button to cancel it in the middle of 10 seconds. Don't let it show "Start!".
If there is no way to cancel, is there any alternative way? Thanks
Upvotes: 1
Views: 596
Reputation: 940
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);
Upvotes: 2