function checkForNotifications(id) {
$http({
method: "POST",
url:( "url"),
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: $.param({id: id}),
})
.then(notificationCheckComplete)
.catch(function(message) {
throw new Error("XHR Failed ",message);
});
function notificationCheckComplete(response, status, headers, config) {
//perform actions based on response, display errors, show popups, etc.
}
setTimeout(function() {checkForNotifications()}, 1000);
}
This code is designed to periodically poll the database for new notifications.
I do not clear the timeout and do not use $timeout. Could this lead to issues such as Chrome freezing or high CPU usage?
How can I properly clear the timeout and verify that it has been cleared?
All functions and UI elements are part of an Angular service/factory without a controller (except for the service call).