一、interval语法
public void rxJavaIntervalExample() {
LogUtils.error(TAG, "rxJavaIntervalExample--start--:" + Thread.currentThread().getName() + "--:" + TimeUtils.getNowString());
Disposable disposable = Observable.interval(3, 2, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Long>() {
@Override
public void accept(Long aLong) throws Exception {
LogUtils.error(TAG, "rxJavaIntervalExample--end--:" + Thread.currentThread().getName() + "--:" + TimeUtils.getNowString() + "---long:" + aLong);
}
});
compositeDisposable.add(disposable);
}
日志
08-18 11:04:38.563 7993-7993/com.example.zhang E/MainPresenter: rxJavaIntervalExample--start--:main--:2018-08-18 11:04:38
08-18 11:04:41.744 7993-7993/com.example.zhang E/MainPresenter: rxJavaIntervalExample--end--:main--:2018-08-18 11:04:41---long:0
08-18 11:04:43.743 7993-7993/com.example.zhang E/MainPresenter: rxJavaIntervalExample--end--:main--:2018-08-18 11:04:43---long:1
08-18 11:04:45.742 7993-7993/com.example.zhang E/MainPresenter: rxJavaIntervalExample--end--:main--:2018-08-18 11:04:45---long:2
08-18 11:04:47.740 7993-7993/com.example.zhang E/MainPresenter: rxJavaIntervalExample--end--:main--:2018-08-18 11:04:47---long:3
总结
1、interval 操作符用于间隔时间执行某个操作,其接受三个参数,分别是第一次发送延迟,间隔时间,时间单位