简体   繁体   English

可观察的超时

[英]Observable timeout

Assume that I have following. 假设我有以下内容。

Observable.range(1,1000)
.flatMap(i -> Observable.just(i)
    .subscribeOn(Schedulers.computation()
    .map(i2 -> calculate(i2))
).subscribe(System.out::println)

In here I have an observable from 1 to 1000 and each number is mapped using calculate()(a large mehod) in different threads.I need to set a timeout until some amount of items returned. 在这里,我有一个从1到1000的observable,并且每个数字在不同的线程中使用calculate()(一个大的mehod)映射。我需要设置一个超时,直到返回一些数量的项目。

    Say I have a timeout of 2 seconds. 假设我超时2秒。
    I need 2-50 items to be subscribed.(At least 2 items should be subscribed but not more than 50 items) 我需要订阅2-50件商品(至少2件商品应订阅但不超过50件)
    If 2 items do not emitted within 2 seconds restart timeout. 如果在2秒内没有发出2项重启超时。
    Say 10 items returned within timeout.Then no problem execute the rest of the code. 说超时内返回10个项目。然后没有问题执行其余的代码。

How can I do this using Rx Java? 我怎么能用Rx Java做到这一点?

这可以使用rx-java中的buffer()而不是使用timeout()来实现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM