Stop Polling Programatically
Hullo,
How do I stop polling when I change a component? Or after receiving a certain result?
apollo: {
patientAppointmentStatus: {
query: AppStatusChecker,
skip: true,
pollInterval: 300, // ms
result (data){
if(data == x){
//STOP POLLING HERE,
setting the skip option to false never seems to work
}
}
thank you
Generally the answer with vue-apollo is "turn it into a function". This gives you access to the component scope, and then you can do whatever you want from there.
Most of the properties also can become a function (like query or variables), but pollInterval is not one of them, so you have to turn the whole smart query into a function. Here you go:
apollo: {
patientAppointmentStatus () {
return {
query: AppStatusChecker,
skip: true,
pollInterval: this.shouldPoll ? 300 : null, // ms
result (data) {
if (data == x) {
this.shouldPoll = false
}
}
}
}
}
Awesome! Great... Let me try this!
@Maxondria Did you get this to work? I did some experiments with this but the query does not seem to respond to this.shouldPoll being set to false, instead it keeps polling. Any ideas?
this.$apollo.queries.patientAppointmentStatus.stopPolling() solved it. Call it anywhere you would want to stop the polling
Thx for the response! Actually I got it to work with stopPolling(), however it seems to only work within the query function itself. Eg:
apollo: {
patientAppointmentStatus () {
return {
query: AppStatusChecker,
skip: true,
pollInterval: 300, // ms
result (data) {
if (data == x) {
this.$apollo.queries.patientAppointmentStatus.stopPolling()
}
}
}
}
}
But I would like to call stopPolling() from one of the methods:
methods: {
stopPoll () {
this.$apollo.queries.thread.stopPolling()
}
},
After stopPoll is called the polling continues anyway. Guess Ill have a look at subscriptions instead :)
Thx for the response! Actually I got it to work with
stopPolling(), however it seems to only work within the query function itself. Eg:apollo: { patientAppointmentStatus () { return { query: AppStatusChecker, skip: true, pollInterval: 300, // ms result (data) { if (data == x) { this.$apollo.queries.patientAppointmentStatus.stopPolling() } } } } }But I would like to call
stopPolling()from one of the methods:methods: { stopPoll () { this.$apollo.queries.thread.stopPolling() } },After
stopPollis called the polling continues anyway. Guess Ill have a look at subscriptions instead :)
Oh, I really can see that in this this.$apollo.queries.thread.stopPolling(), you're calling the thread query to stop polling. is it the right query? Because this should really work. I can call that line of code in any of the component methods. It can only poll again after you reload the component, or leave it and come back to it later in routing