I'm working on creating API polling on some async function which is called from another async function. Something like below code:
public generatePreview() {
this.apiService.firstAPI().subscribe(async headers => {
// Do some processing over here
await this.getRows();
});
}
public async getRows() {
this.apiService.secondAPI().subscribe(async rows => {
if (rows.status === 'INGESTION_IN_PROGRESS') {
console.log('inside');
setTimeout(()=>{return await this.getRows()}, 5000);
} else if (rows.status === 'COMPLETED') {
// Stopping Logic
}
});
}
Explanation : generatePreview function calls a firstAPi function, calls out getRows function which has the polling logic . If async call response has status 'INGESTION_IN_PROGRESS', It should call getRows again(with some delay). When I put it inside setTimeout, I get the following error ''await' expression is only allowed within an async function.'.
I am looking for best options to achieve the polling with some timer.