我有一个n个可观察的数组,我想一次发出4个请求,然后再发出4个,直到最后



如何限制并行请求?

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);
});

您可以将mergeAll用于并发请求。

参考编号:https://levelup.gitconnected.com/limit-concurrency-with-rxjs-and-promises-78590d2c85d0

相关内容

最新更新