0

I created a interval that executing each second. Inside that interval i have a for loop that submitting a request to a server throw an Observable. I want to stop the interval when a condition turns to true. Although the condition is true the interval keep going.

private setStatusChecker() {
    const taskInterval = setInterval(() => {
      this.uploadedFiles.forEach((task, index) => {
        if (this.uploadedFiles.length === this.completedTasksNumber || this.stopGetUploadStatusInterval === true) {
          clearInterval(taskInterval);
          this.uploadingProcessActive = false;
          this.stopGetUploadStatusInterval = true;
        }
        if (task.state !== 'SUCCESS') {
          this.getUploadStatus(task.id).subscribe((response: any) => {
            if (response.info === null) {
              return;
            }
            const fileStatus: UploadStatus = {
              id: task.id,
              state: response.state,
            };
            this.uploadedFiles[index] = fileStatus;
          });
        }
        if (task.state === 'SUCCESS') {
          this.completedTasksNumber++;
          task.state = 'COMPLETED';
        }
      });
      this.uploadedFilesCurrentStatus.next(this.uploadedFiles);
    }, 1000);
  }
Igor.ro
  • 37
  • 2
  • 9

0 Answers0