Hongbo Miao
Hongbo Miao

Reputation: 49754

How to cancel Meteor.setTimeout?

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

Answers (1)

Philip Pryde
Philip Pryde

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

Related Questions