RxJava2.x-skip

2018-08-18  本文已影响1人  河马过河

一、skip语法

 public Observable<Integer> getRxJavaCreateExampleData() {
        return Observable.create(new ObservableOnSubscribe<Integer>() {
            @Override
            public void subscribe(ObservableEmitter<Integer> emitter) {
                LogUtils.debug(TAG, "getRxJavaCreateExampleData---:" + Thread.currentThread().getName() + "--:" + 1);
                emitter.onNext(1);

                LogUtils.debug(TAG, "getRxJavaCreateExampleData---:" + Thread.currentThread().getName() + "--:" + 2);
                emitter.onNext(2);

                LogUtils.debug(TAG, "getRxJavaCreateExampleData---:" + Thread.currentThread().getName() + "--:" + 3);
                emitter.onNext(3);
                emitter.onComplete();
                LogUtils.debug(TAG, "getRxJavaCreateExampleData---:" + Thread.currentThread().getName() + "--:" + 4);
                emitter.onNext(4);

            }
        });
    }
  public void rxJavaSkipExample() {
        Disposable disposable = model.getRxJavaCreateExampleData()
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .skip(2)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Integer>() {
                    @Override
                    public void accept(Integer integer) throws Exception {
                        LogUtils.error(TAG, "rxJavaSkipExample--:" + Thread.currentThread().getName() + "-Consumer-:" + integer);
                    }
                });
        compositeDisposable.add(disposable);
    }

日志

08-18 14:04:40.560 21252-21744/com.example.zhang D/MainModel: getRxJavaCreateExampleData---:RxCachedThreadScheduler-1--:1
    getRxJavaCreateExampleData---:RxCachedThreadScheduler-1--:2
    getRxJavaCreateExampleData---:RxCachedThreadScheduler-1--:3
    getRxJavaCreateExampleData---:RxCachedThreadScheduler-1--:4
08-18 14:04:40.564 21252-21252/com.example.zhang E/MainPresenter: rxJavaSkipExample--:main-Consumer-:3

总结

1、skip(long count) count 跳过count个


河马过河微信公众号.jpg
上一篇下一篇

猜你喜欢

热点阅读