首页 > 编程 > Java > 正文

RxJava2的使用,以及RxJava的比较

2019-11-09 17:45:49
字体:
来源:转载
供稿:网友
Rxjava2与RxJava的比较
RxJava最核心的东西就是Observable和Observer。
Observable会发出数据Observer可以在Observable发出数据  
RxJava2最核心的是Flowable和Consumer
 

配合retrofit2需要引入的库compile 'com.squareup.retrofit2:retrofit:2.1.0'compile 'com.squareup.retrofit2:converter-gson:2.1.0'compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'compile 'com.squareup.okhttp3:logging-interceptor:3.5.0'compile 'io.reactivex.rxjava2:rxjava:2.0.4'compile 'io.reactivex.rxjava2:rxandroid:2.0.0'
延时操作Flowable.timer(600, TimeUnit.MILLISECONDS).subscribe(aLong -> PRogressDialog.cancel(),        throwable -> throwable.printStackTrace());
输出使用lambda表达式 Flowable.just("Hello world").subscribe(System.out::println);未使用lambda表达式Flowable.just("Hello world")  .subscribe(new Consumer<String>() {      @Override public void accept(String s) {          System.out.println(s);      }  );
Flowable.fromCallable(() -> {    Thread.sleep(1000); //  imitate expensive computation    return "Done";})  .subscribeOn(Schedulers.io())  .observeOn(Schedulers.single())  .subscribe(System.out::println, Throwable::printStackTrace);
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表