I am facing an issue with stopping a subscription process.
Here is the current code I am using:
if (Meteor.isClient) {
Meteor.autorun(function(){
var query;
query = Session.get('search.query');
if (!query) return;
if (Envi.temp.searchSubscribtion) {
console.log('Subscription for search needs to be stopped ... ');
Envi.temp.searchSubscribtion.stop();
}
Envi.temp.searchSubscribtion = Meteor.subscribe('search', query, {
onReady : function () {
console.log('Finished.');
}
});
});
}
'Env' is a global function where subscriptions are temporarily stored in temp.searchSubscribtion
.
The issue at hand: when I change the value of search.query
to a query that retrieves all items, the "Finished" console log is displayed after about 1 minute.
However, when I change search.query
to a query that retrieves only a few items, the "Finished" console log displays after approximately 5 seconds.
It seems there is a difference in processing time between long and short queries.
My goal now is to cancel the currently running subscription when a query is changed, and start a new one. However, when I switch from a long query to a short query immediately, the "Finished" console log still takes more than 1 minute to display.
Even though "
Envi.temp.searchSubscribtion.stop();
" is being executed (as seen in the console log), the subscription does not stop - it appears that the server finishes the first subscription before moving on to the second, as if they are queued.
Do you have any ideas on how to effectively cancel a running subscription?