想要使用Angular/Ionic中的forkjoin以批量格式调用多个API调用
我有一系列请求:
let array = [req1,req2,req3.....,req(n)]
目前,我仅在获得所有请求响应后才使用forkjoin致电订户。现在,我想修改代码以批量拨打API调用,但是只有在完成所有批次响应后才致电订户,这是可能的吗?
示例
public demoCalls() {
let demoForkJoin
var a = [req1,req2,....,req45]
a.map((data,index)=>{
demoFrokJoin[index] = this.http.post()
})
forkJoin(demoForkJoin)
}
现在而不是这个,我想在批处理中致电10-10 req。 1000ms之后,每10个REQ将被调用
,并且只有在从所有API中响应后才调用一个订户。 (全部45个API)
demoCall().subscribe(res=>{
// this subscribe only once after all calls are completed and got success result
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议使用一些RXJS运算符的并发值,而不是批处理。
Mergemap
例如提供此值。完成一个可观察到的可观察后,下一个可观察的可订阅。为完成操作添加最终确定
。下面的示例具有2个并发请求,
请参见stackblitz上的此操作:
Instead of batching I recommend to use the concurrent value of some rxjs operators.
mergeMap
for example provides this value. After completing one observable, the next observable becomes subscribed to. Addfinalize
for the finish action.Following example has 2 concurrent requests
See this in action on Stackblitz: https://stackblitz.com/edit/typescript-cmylca?file=index.ts