I'm performing a database count through a server method. Users can select how they want the count to be performed and then invoke the method.
My problem is that the count can take some time and a user might change their mind while the method is running and request a different count. Is there any way for me to cancel the invoked method and run a new count?
I've thought this.unblock() might work; it will allow a new method to be run, but it won't cancel the old method. I've also considered pre-counting and then just using a lookup, but there are too many selector combinations.
Here's my code, it's fairly simple:
//Server
Meteor.methods({
getFilterCount: function(oFilterSelector) {
return clMaBldgs.find(oFilterSelector, {}).count();
}
});
//Client
Meteor.call('getFilterCount', oFilterSelector, function (error, result) {
//do some stuff
});
Cancelling an already-made method call to server from client is not possible.
But if your method are called multiple times in a short interval, and you only care about the last call's result. You could use debounce to delay execution for some times. This will help reduce unnecessary calls to server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With