美文网首页
RxJava2.x-skip

RxJava2.x-skip

作者: 河马过河 | 来源:发表于2018-08-18 14:05 被阅读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

    相关文章

      网友评论

          本文标题:RxJava2.x-skip

          本文链接:https://www.haomeiwen.com/subject/evrfiftx.html