By taking response of an API and passing it to another function, using the response ID inside a setInterval for checking the status of an operation for implementing progress bar.
For each time sending the ID by API inside the function returns the status at each instant.
Once the status is "SUCESS" or "Failure" I need to exit the function and perform the next step of operations under the function call it is not happening. If status is "PROGRESS" need the loop to me run for 1 minute and exit.
Here I'm my case I'm using clearInterval if the status is "SUCESS" to break the loop.
Why is is not exiting function after the process is completed?
Is there any alternate way to exit the loop after "SUCESS" or "Failure*"
this.userdat.sendData(data).subscribe((res:any)=>{
this.checkProgress(res.Id);
//DO THIS -->Not coming here after exceuction
})
checkProgress(id: any) {
this.StatFlag = false;
this.interval = setInterval(() => {
if (!this.StatFlag) {
this.userdat.operationStatus(id).subscribe((statres: any) => {
switch (statres.status) {
case "PROGRESS":
this.stepper.selectedIndex = 1;
break;
case "SUCESS":
this.stepper.selectedIndex = 2;
this.steppershow = false;
this.StatFlag = true;
clearInterval(this.interval)
break;
case "FAILED":
this.steppershow = true;
clearInterval(this.interval)
this.StatFlag = true;
break;
}
});
}
}, 50000);
<mat-horizontal-stepper *ngIf="showsteps0" #stepper>
<mat-step label="SUBMITTED" >
</mat-step>
<mat-step label=" IN progress" >
</mat-step>
<mat-step *ngIf="!steppershow" label="Complteted" >
</mat-step>
<mat-step label="Failed" *ngIf="steppershow">
</mat-step>
</mat-horizontal-stepper>
I have tried creating a new block after the clearInterval
and setting flag for clearInterval
it doesn't work as expected.