我有post http请求,它发送大量数据,并包含可能相当大的数组。我试图拆分请求,所以我想发送一个包含所有数据的请求,我想将它分块发送。
// service.ts
saveRequest(request: AutomationChecklist) {
return this.http
.post(this.url + this.saveRequestUrl, request, this.options)
.map((response: Response) => {
return response.json();
});
}
// automationChecklist.ts
export class AutomationChecklist {
siteInformation: siteInformation;
orderInformation: OrderInformation;
requestInformation: RequestInformation;
contactInformation: ContactInformation;
installations: Installation[]; // save this separately, this one can be quite large
completedAutomation: number;
progress: number;
}处理此请求的可能解决方案是什么?我读过关于forkjoin的文章,但不确定它是否适合这种情况?
发布于 2019-09-04 12:46:28
如果您想要分离installations,可以使用concatMapTo操作符来完成:
saveRequest(automations: AutomationChecklist, installations: Installation[]) {
return this.http
.post(this.url + this.saveRequestUrl, automations, this.options)
.pipe(concatMapTo(this.http.post(this.url + /*installations save url*/, installations, this.options)))
.map((response: Response) => {
return response.json();
});
}该解决方案的缺点:
这取决于你想做什么,如果你接受不一致,它可能是一个很好的解决办法,以减轻你的要求。
发布于 2019-09-04 12:10:32
假设您有一个数据数组,下面的代码将以3的并发性发布到api。
array=[data,data,data]
const concurrency=3
from(array).pipe(mergeMap(request=>this.http
.post(this.url + this.saveRequestUrl, request, this.options),null,concurrency)https://stackoverflow.com/questions/57784571
复制相似问题