Suppose I have the following polling function:
function pollingFunc(taskId){
setTimeout(function() {
$.ajax({
url: '/endpoint',
type: 'POST',
data: { 'celery_task_id': taskId },
success: function(response){
if(response.celery_ready) {
console.log('CELERY IS READY')
} else {
console.log('polling')
pollingFunc(response.task_id)
}
}
})
}, 5000);
}
When I invoke it, the success callback is never invoked or it might be, but my console.logs never appear. Instead after a while I get
Uncaught RangeError: Maximum call stack size exceeded
So my function is running recursively, but in the way that I would want it to. I would hope at lease the console log before my recursive calls start would print in the console, but it doesn't. I have confirmed that my backend endpoint is operating correctly and is returning json, so I suspect there is something in my javascript code that I am missing. Anyone have any idea?