I have implemented the a polling using DeferredResult in Spring and on the client side I handle the data I receive form the server.
In the client side I have a simple page with plain javascript:
// start polling (ignore placeholder)
function polling() {
console.log("call with fetch");
fetch('%@[urlPolling]')
.then(function(response) {
console.log(response);
return response.text();
}).then(function(data) {
console.log(data); // this will be a string
var dataJson = JSON.parse(data);
if (dataJson.status == "OK" || dataJson.status == "KO") {
addLoaderEffect();
console.log("completato");
sendPollingResult();
} else if (dataJson.status == "ERROR") {
console.log("error from server, executing polling again");
setTimeout(polling, 3000);
}
})
.catch((error) => {
console.error('Error:', error);
setTimeout(polling, 3000);
});
}
polling();
There is a way to understand when the connection with the server is closed? For example during a release the instance will be replaced and the client will wait for an answer indefinitely. There is a way to handle such scenario?