0

I want to call the verifyFile api every 2 seconds for which I have put set interval. I have used for loop to access the individual file id because there could be many and you can only send it one at a time. I think set interval inside for loop is not working as expected. Is there a way to do it without the for loop.

 checkFileStatus() {
    for (let index = 0; index < this.currentlyRunning.length; index++) {
      const fileId = this.currentlyRunning[index].id;
       let repeat = setInterval(() => {
       let file_id = {
         userFileId: fileId
       }
       console.log(file_id)
       this.auth.verifyFile(file_id).subscribe((res: any)=>{ 
       console.log(res);
       if(res.percent === 100) {
        clearInterval(repeat);
        this.updateFileHistory();
       }
     },(err)=>{ console.log(err)});
     }, 2000);
    }
  }

}
EdChum
  • 376,765
  • 198
  • 813
  • 562
zuyi
  • 459
  • 2
  • 8
  • 17

0 Answers0