.subscribeOn(Schedulers.io())
.unsubscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber);

每次切换线程的操作

 

变换封装操作

Observable.Transformer schedulersTransformer() {
        return new Observable.Transformer() {
            @Override
            public Object call(Object observable) {
                return ((Observable)  observable).subscribeOn(Schedulers.io())
                        .unsubscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread());
            }
        };
    }

使用的时候

RetrofitClient.singletonDemoService("http://api/data/")
.requestNet("xx","1")
.compose(schedulersTransformer())
.subscribe(subscriber);

水一波

posted on 2017-10-25 09:18  翻滚的咸鱼  阅读(1450)  评论(0编辑  收藏  举报