Reputation: 1283
nodeJS is driving me crazy, i'm trying to resend an API get request until its finished processing, can't get this to work, help..
function checkReturnValue(done){
request(options, function (error, response) {
if (error) throw new Error(error);
if (response.body.scan_results.progress_percentage != 100)
{
console.log('if');
setTimeout(checkReturnValue(done), 50);
}
else
{
console.log('else');
return done(response.body);
}
});
};
checkReturnValue ((body) => {
console.log(body);
});
Upvotes: 0
Views: 30
Reputation: 12071
You are using the result of checkReturnValue(done)
as the function to call after the timeout.
Try supplying a function to be invoked instead:
setTimeout(() => checkReturnValue(done), 50);
Upvotes: 1