简体   繁体   中英

How to add delay for some items in RxJava

I want to implement a RxChain for the following purpose:

An observable source is emitting two types of data (S, E). Now I want an observable/flowable which will emit all the S immediately but it should emit the latest E after a given delay (10 sec) from the first emission of E if no S comes in the meantime.

在此处输入图像描述

Instead of having 1 observable source emitting both S and E, you could instead split them into 2 observables, add a throttleLast 10s on the "E stream" and then merge them together

eg

Observable<String> sStream = source.filter(x -> x.type == Types.S);
Observable<String> eStream = source.filter(x -> x.type == Types.E).throttleLast(10, TimeUnit.SECONDS);


Observable.merge(sStream, eStream).subscribe(...);

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