Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor - Cancelling a Server Method from the Client

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
});
like image 421
Adam Avatar asked Jul 24 '14 21:07

Adam


1 Answers

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.

like image 59
kkkkkkk Avatar answered Nov 16 '22 12:11

kkkkkkk