Home > database >  I have an array of n number of observable, and i want to make 4 request at a time then again 4, till
I have an array of n number of observable, and i want to make 4 request at a time then again 4, till

Time:11-03

how do i limit parallel request?

...

for (let offset = 0; offset < file[0].size; offset = chunkSize) { const chunk = file[0].slice(offset, offset chunkSize);

    const blockId = String(Math.floor(100000   Math.random() * 900000));
    const base64BlockId = btoa(blockId);

    this.blockids.push(base64BlockId);

    request.push(this.blobService.addNewVideo(uniqueName, chunk, base64BlockId));
  }

 forkJoin(
    request.map(req => req.pipe(
      tap((event: HttpEvent<any>) => {
        switch (event.type) {
          case HttpEventType.UploadProgress:
            this.progress = Math.round((event.loaded / event.total!) * 100);
            // console.log(`uploaded! ${this.progress}%`);
            break;
          case HttpEventType.Response:
            console.log('Successfully uploaded', event.body," : ",event.status,event.statusText);
        }
      })
    ))
  ).subscribe(() => {
    this.commit(uniqueName);
  });

...

CodePudding user response:

You can use mergeAll for concurrent requests.

Ref: https://levelup.gitconnected.com/limit-concurrency-with-rxjs-and-promises-78590d2c85d0

  • Related