In our framework we have to wait and poll until a specific response to do the next API call. For that we have following function,
public async pollUntil(request: () => Promise<any>,condition: (res: any) => boolean) {
const responseData = await request();
const conditionResponse = condition(responseData);
if (!conditionResponse) {
await setTimeout(5000);
await this.pollUntil(request, condition);
} else {
this.response = responseData;
}
}
The usage is
await ApiCall.pollUntil(() => ApiCall.get(url),this.statusAbortComplete);
We need to poll until the response has following
private statusAbortComplete(response: any) {
return !!(response.state === 'abortDone' && response.msg === 'empty');
}
To complete this task it's takes around 10minuts and sometimes less than 10minuts. With the current implementation we have to change the global cucumber timeout for setps for huge number
// <number> timeout for step definitions
timeout: 900000,
This timeout has an impact on other functions that fail. So need to add a timeout to the pollUntil() function to stop looping once the timeout is reached. There are other similar type of APIs calls we need to do. And those takes different time to get the final response. We might need to pass the different timeout for pollUntil() function calls. I'm new to typescripts and need help figuring out how to do it.