Answer the question
In order to leave comments, you need to log in
What to do with long polling in SPA?
Hello. There are difficulties in organizing long polling. The task is simple, there is data in the table, let's call it items, each item has some kind of state or task that needs to be checked and when it changes on the server, change the status in the table.
checkTask(item) {
if (!item.active) {
fetch(`/items/${item.id}/`)
.then(response => response.json())
.then((response) => {
if (!item.active) {
setTimeout(() => this.checkTask(item), CHECK_INTERVAL);
} else {
// Do something here, like toast
// Clear task
item.active = true;
}
});
}
},
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question