Utilizing the following function to retrieve users from a REST API, paginated by offset. Upon successful callback, the function recursively calls itself with a new offset to fetch the next set of users.
Issue: When I change or exit the view, the FetchAttendee-Function
continues running until all users are fetched. However, for better performance, I want to halt the process of fetching users.
fetchAttendees(event_id, offset);
function fetchAttendees(event_id, offset) {
AttendeeFactory(offset).show({id: event_id},
function success(response) {
[ DO SOMETHING WITH RESPONSE ]
fetchAttendees(event_id, offset);
},
function (error) {
});
}
Therefore, is it feasible to prevent the fetchAttendee-Function from being called when leaving the view Event?
$scope.$on("$ionicView.leave", function(scopes, states) {
[ ...]
});
AttendeeFactory
.factory('AttendeeFactory', function ($resource) {
return function (offset) {
return $resource('http://10.0.0.6:8000/backend/attendees/:id/', {}, {
show: { method: 'GET', headers: {'attendee-offset': offset}, isArray: true }
});
};
})