[英]Api calls chaining to some limit Rxjava2 + Retrofit2
I'm using Retrofit2
with Rxjava
to make API calls. 我使用
Retrofit2
与Rxjava
来进行API调用。 I have to make multiple API calls ( of the same API ), let's say 100 of them. 我必须进行多个(相同API的)API调用,假设其中有100个。 Now I want, at max 5 of them to be executed parallelly.
现在,我希望最多并行执行5个。 So if 5 API calls are going on, 6th one should wait.
因此,如果正在进行5个API调用,则应该等待第6个。 As soon as any one of those ongoing 5 calls is completed, 6th one should start.
这些正在进行的5个通话中的任何一个通话一旦结束,第6个应立即开始。 I don't want this in bulk of 5 where first 5 completes and only after that next 5 happens.
我不希望在最初的5个完成且仅在接下来的5个发生之后才使用5个。
I'm not sure how can I achieve with Rxjava
and that's why I don't have any snippet to post. 我不确定如何使用
Rxjava
来实现,这就是为什么我没有要发布的Rxjava
的原因。 Any help would be great 任何帮助都会很棒
RxJava has certain operators that can limit the number of threads in action. RxJava具有某些运算符,可以限制正在使用的线程数。
observable
.flatMap( input -> apiCallReturningObservable( input ), 5 )
.subscribe();
will have a maximum of 5 invocations of apiCallReturningObservable()
at one time. 一次最多可调用
apiCallReturningObservable()
5次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.