In my Vue 2.0 app, I have a line of code that calls this.refreshState()
every minute using the following interval:
this.scheduler = setInterval(() => this.refreshState(), 60 * 1000)
Later in the code, I need to ensure that the execution loop is halted and that any instance of this.refreshState()
currently running from the scheduler is also stopped (even if it's mid-operation).
Currently, I am using :
clearInterval(this.scheduler)
I am unsure whether clearInterval
blocks the current execution. Unfortunately, I couldn't find an answer in the documentation.
For reference, here is the code for refreshState
:
refreshState: function () {
// API call to backend
axios.get("/api/refreshState")
.then(response => {
this.states = response.data.states
})
.catch((err) => console.log(err))
}
Here's a scenario where I am concerned:
alterState: function (incremental_state) {
clearInterval(this.scheduler) // ???
axios.post("/api/alterState", incremental_state)
.then(() => {
this.refreshState()
this.scheduler = setInterval(() => this.refreshState(), 60 * 1000)
})
.catch((err) => { console.log(error) })
}
I want to ensure that upon exiting alterState
, the variable this.states
incorporates the incremental state added.