RxJava2 Flowable delay delaySubscription(辅助操作符)
delay (辅助操作符)
目录
1 dealy接口
|
Returns a Flowable that delays the emissions of the source Publisher via another Publisher on a per-item basis. 返回一个Flowable,它基于每个项目通过另一个Publisher延迟源Publisher的排放。 |
|
Returns a Flowable that emits the items emitted by the source Publisher shifted forward in time by a specified delay. 返回一个Flowable,它发出由源Publisher按时间向前移动指定延迟的项。 |
|
Returns a Flowable that emits the items emitted by the source Publisher shifted forward in time by a specified delay. 返回一个Flowable,它发出由源Publisher按时间向前移动指定延迟的项(并设置是否延迟error处理) |
|
Returns a Flowable that emits the items emitted by the source Publisher shifted forward in time by a specified delay. 返回一个Flowable,它发出由源Publisher按时间向前移动指定延迟的项。(延迟策略可以自己自定义 |
|
Returns a Flowable that emits the items emitted by the source Publisher shifted forward in time by a specified delay. 返回一个Flowable,它发出由源Publisher按时间向前移动指定延迟的项。(延迟策略可以自己自定义 |
|
Returns a Flowable that delays the subscription to and emissions from the source Publisher via another Publisher on a per-item basis. 返回一个Flowable,它基于每个项目延迟通过另一个Publisher对源Publisher的订阅和排放。 |
2 delay图解
图1
图2
3 delay测试用例
测试代码
public void delay() {
System.out.println(System.currentTimeMillis() + "|######delay#####,time");
Flowable.just("item1").delay(3, TimeUnit.SECONDS)
.subscribe(new Consumer<String>() {
@Override
public void accept(String s) throws Exception {
System.out.println(System.currentTimeMillis() + "|s =" + s);
}
});
}
输出
I/System.out: 1538820032261|######delay#####,time
I/System.out: 1538820035263|s =item1
4 delay测试用例说明
上面的例子我沒用@Test单元测试方式写,因为测试的时候发现无法打印结果,而是直接使用android的onclick调用,才能看出结果,句打印相隔3s以上。
这里使用最简单的一种说明,其他重载方法也是一样的功能,有的增加delayError,处理error延迟,以及Scheduler作为延迟调度。
5 delaySubscription操作符
delaySubscription和delay不同,delaySubscription是延迟订阅源Publisher,订阅延迟,对于冷Publisher自然也就延迟收到观察数据,但是对于热Publisher就不一样了,因为他在创建后就开始发射数据,不是非得被订阅了才发发射数据,所以延迟订阅热观察源可能会丢失订阅前被发射的数据。
Returns a Flowable that delays the subscription to the source Publisher by a given amount of time. 返回一个Flowable,它将给订阅源的订阅延迟一段给定的时间。 |
|
Returns a Flowable that delays the subscription to the source Publisher by a given amount of time, both waiting and subscribing on a given Scheduler. 返回一个Flowable,它将给订阅源的订阅延迟给定的时间,包括在给定的Scheduler上等待和订阅。 |
|
Returns a Flowable that delays the subscription to this Publisher until the other Publisher emits an element or completes normally. 返回一个Flowable,它会延迟对此Publisher的订阅,直到另一个Publisher发出元素或正常完成为止。 |
查看其它操作符