简体   繁体   中英

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.

    Say I have a timeout of 2 seconds.
    I need 2-50 items to be subscribed.(At least 2 items should be subscribed but not more than 50 items)
    If 2 items do not emitted within 2 seconds restart timeout.
    Say 10 items returned within timeout.Then no problem execute the rest of the code.

How can I do this using Rx Java?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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