rx.Observable.concat()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(14.3k)|赞(0)|评价(0)|浏览(174)

本文整理了Java中rx.Observable.concat()方法的一些代码示例,展示了Observable.concat()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.concat()方法的具体详情如下:
包路径:rx.Observable
类名称:Observable
方法名:concat

Observable.concat介绍

[英]Returns an Observable that emits the items emitted by each of the Observables emitted by the source Observable, one after the other, without interleaving them.

Scheduler: concat does not operate by default on a particular Scheduler.
[中]返回一个Observable,该Observable发出源Observable发出的每个Observable发出的项,一个接一个地发出,而不交错它们。
调度器:默认情况下,concat不会在特定的调度器上运行。

代码示例

代码示例来源:origin: jaydenxiao2016/AndroidFire

} else {
  return Observable.concat(fromCache, fromNetwork).first();

代码示例来源:origin: smuyyh/BookReader

@Override
public void getBookListTags() {
  String key = StringUtils.creatAcacheKey("book-list-tags");
  Observable<BookListTags> fromNetWork = bookApi.getBookListTags()
      .compose(RxUtil.<BookListTags>rxCacheListHelper(key));
  //依次检查disk、network
  Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, BookListTags.class), fromNetWork)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new Observer<BookListTags>() {
        @Override
        public void onCompleted() {
          mView.complete();
        }
        @Override
        public void onError(Throwable e) {
          LogUtils.e("getBookListTags:" + e.toString());
          mView.showError();
        }
        @Override
        public void onNext(BookListTags tags) {
          mView.showBookListTags(tags);
        }
      });
  addSubscrebe(rxSubscription);
}

代码示例来源:origin: smuyyh/BookReader

.concat(RxUtil.rxCreateDiskObservable(key, BookMixAToc.mixToc.class), fromNetWork)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BookMixAToc.mixToc>() {

代码示例来源:origin: smuyyh/BookReader

public void getHotWordList() {
  String key = StringUtils.creatAcacheKey("hot-word-list");
  Observable<HotWord> fromNetWork = bookApi.getHotWord()
      .compose(RxUtil.<HotWord>rxCacheListHelper(key));
  //依次检查disk、network
  Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, HotWord.class), fromNetWork)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new Observer<HotWord>() {
        @Override
        public void onNext(HotWord hotWord) {
          List<String> list = hotWord.hotWords;
          if (list != null && !list.isEmpty() && mView != null) {
            mView.showHotWordList(list);
          }
        }
        @Override
        public void onCompleted() {
        }
        @Override
        public void onError(Throwable e) {
          LogUtils.e("onError: " + e);
        }
      });
  addSubscrebe(rxSubscription);
}

代码示例来源:origin: smuyyh/BookReader

public void getBookDetailReviewList(String bookId, String sort, final int start, int limit) {
  String key = StringUtils.creatAcacheKey("book-detail-review-list", bookId, sort, start, limit);
  Observable<HotReview> fromNetWork = bookApi.getBookDetailReviewList(bookId, sort, start + "", limit + "")
      .compose(RxUtil.<HotReview>rxCacheListHelper(key));
  //依次检查disk、network
  Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, HotReview.class), fromNetWork)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new Observer<HotReview>() {
        @Override
        public void onCompleted() {
          mView.complete();
        }
        @Override
        public void onError(Throwable e) {
          LogUtils.e("getBookDetailReviewList:" + e.toString());
          mView.showError();
        }
        @Override
        public void onNext(HotReview list) {
          boolean isRefresh = start == 0 ? true : false;
          mView.showBookDetailReviewList(list.reviews, isRefresh);
        }
      });
  addSubscrebe(rxSubscription);
}

代码示例来源:origin: smuyyh/BookReader

@Override
public void getCategoryList(String gender, final String major, String minor, String type, final int start, int limit) {
  String key = StringUtils.creatAcacheKey("category-list", gender, type, major, minor, start, limit);
  Observable<BooksByCats> fromNetWork = bookApi.getBooksByCats(gender, type, major, minor, start, limit)
      .compose(RxUtil.<BooksByCats>rxCacheListHelper(key));
  //依次检查disk、network
  Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, BooksByCats.class), fromNetWork)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new Observer<BooksByCats>() {
        @Override
        public void onCompleted() {
          mView.complete();
        }
        @Override
        public void onError(Throwable e) {
          LogUtils.e("getCategoryList:" + e.toString());
          mView.showError();
        }
        @Override
        public void onNext(BooksByCats booksByCats) {
          mView.showCategoryList(booksByCats, start == 0 ? true : false);
        }
      });
  addSubscrebe(rxSubscription);
}

代码示例来源:origin: smuyyh/BookReader

@Override
public void getCategoryListLv2() {
  String key = StringUtils.creatAcacheKey("category-list2");
  Observable<CategoryListLv2> fromNetWork = bookApi.getCategoryListLv2()
      .compose(RxUtil.<CategoryListLv2>rxCacheListHelper(key));
  //依次检查disk、network
  Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, CategoryListLv2.class), fromNetWork)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new Observer<CategoryListLv2>() {
        @Override
        public void onCompleted() {
          mView.complete();
        }
        @Override
        public void onError(Throwable e) {
          LogUtils.e("getCategoryListLv2:" + e.toString());
          mView.showError();
        }
        @Override
        public void onNext(CategoryListLv2 categoryListLv2) {
          mView.showCategoryList(categoryListLv2);
        }
      });
  addSubscrebe(rxSubscription);
}

代码示例来源:origin: smuyyh/BookReader

@Override
public void getRankList() {
  String key = StringUtils.creatAcacheKey("book-ranking-list");
  Observable<RankingList> fromNetWork = bookApi.getRanking()
      .compose(RxUtil.<RankingList>rxCacheBeanHelper(key));
  //依次检查disk、network
  Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, RankingList.class), fromNetWork)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new Observer<RankingList>() {
        @Override
        public void onNext(RankingList data) {
          if (data != null && mView != null) {
            mView.showRankList(data);
          }
        }
        @Override
        public void onCompleted() {
          mView.complete();
        }
        @Override
        public void onError(Throwable e) {
          LogUtils.e("getRankList:" + e.toString());
          mView.complete();
        }
      });
  addSubscrebe(rxSubscription);
}

代码示例来源:origin: smuyyh/BookReader

@Override
public void getGirlBookDisscussionList(String sort, String distillate, final int start, int limit) {
  String key = StringUtils.creatAcacheKey("girl-book-discussion-list", "girl", "all", sort, "all", start + "", limit + "", distillate);
  Observable<DiscussionList> fromNetWork = bookApi.getGirlBookDisscussionList("girl", "all", sort, "all", start + "", limit + "", distillate)
      .compose(RxUtil.<DiscussionList>rxCacheListHelper(key));
  //依次检查disk、network
  Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, DiscussionList.class), fromNetWork)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new Observer<DiscussionList>() {
        @Override
        public void onCompleted() {
          mView.complete();
        }
        @Override
        public void onError(Throwable e) {
          LogUtils.e("onError: " + e.toString());
          mView.showError();
        }
        @Override
        public void onNext(DiscussionList list) {
          boolean isRefresh = start == 0 ? true : false;
          mView.showGirlBookDisscussionList(list.posts, isRefresh);
        }
      });
  addSubscrebe(rxSubscription);
}

代码示例来源:origin: smuyyh/BookReader

@Override
public void getBookDisscussionList(String block, String sort, String distillate, final int start, int limit) {
  String key = StringUtils.creatAcacheKey("book-discussion-list", block, "all", sort, "all", start + "", limit + "", distillate);
  Observable<DiscussionList> fromNetWork = bookApi.getBookDisscussionList(block, "all", sort, "all", start + "", limit + "", distillate)
      .compose(RxUtil.<DiscussionList>rxCacheListHelper(key));
  //依次检查disk、network
  Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, DiscussionList.class), fromNetWork)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new Observer<DiscussionList>() {
        @Override
        public void onCompleted() {
          mView.complete();
        }
        @Override
        public void onError(Throwable e) {
          LogUtils.e("getBookDisscussionList:" + e.toString());
          mView.showError();
        }
        @Override
        public void onNext(DiscussionList list) {
          boolean isRefresh = start == 0 ? true : false;
          mView.showBookDisscussionList(list.posts, isRefresh);
        }
      });
  addSubscrebe(rxSubscription);
}

代码示例来源:origin: smuyyh/BookReader

@Override
public void getBookHelpList(String sort, String distillate, final int start, int limit) {
  String key = StringUtils.creatAcacheKey("book-help-list", "all", sort, start + "", limit + "", distillate);
  Observable<BookHelpList> fromNetWork = bookApi.getBookHelpList("all", sort, start + "", limit + "", distillate)
      .compose(RxUtil.<BookHelpList>rxCacheListHelper(key));
  //依次检查disk、network
  Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, BookHelpList.class), fromNetWork)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new Observer<BookHelpList>() {
        @Override
        public void onCompleted() {
          mView.complete();
        }
        @Override
        public void onError(Throwable e) {
          LogUtils.e("getBookHelpList:" + e.toString());
          mView.showError();
        }
        @Override
        public void onNext(BookHelpList list) {
          boolean isRefresh = start == 0 ? true : false;
          mView.showBookHelpList(list.helps, isRefresh);
        }
      });
  addSubscrebe(rxSubscription);
}

代码示例来源:origin: smuyyh/BookReader

@Override
public void getBookDetailDiscussionList(String bookId, String sort, final int start, int limit) {
  String key = StringUtils.creatAcacheKey("book-detail-discussion-list", bookId, sort, start, limit);
  Observable<DiscussionList> fromNetWork = bookApi.getBookDetailDisscussionList(bookId, sort, "normal,vote", start + "", limit + "")
      .compose(RxUtil.<DiscussionList>rxCacheListHelper(key));
  //依次检查disk、network
  Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, DiscussionList.class), fromNetWork)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new Observer<DiscussionList>() {
        @Override
        public void onCompleted() {
          mView.complete();
        }
        @Override
        public void onError(Throwable e) {
          LogUtils.e("getBookDetailDiscussionList:" + e.toString());
          mView.showError();
        }
        @Override
        public void onNext(DiscussionList list) {
          boolean isRefresh = start == 0 ? true : false;
          mView.showBookDetailDiscussionList(list.posts, isRefresh);
        }
      });
  addSubscrebe(rxSubscription);
}

代码示例来源:origin: smuyyh/BookReader

@Override
public void getSearchResultList(String author) {
  String key = StringUtils.creatAcacheKey("search-by-author", author);
  Observable<BooksByTag> fromNetWork = bookApi.searchBooksByAuthor(author)
      .compose(RxUtil.<BooksByTag>rxCacheListHelper(key));
  //依次检查disk、network
  Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, BooksByTag.class), fromNetWork)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new Observer<BooksByTag>() {
        @Override
        public void onNext(BooksByTag booksByTag) {
          if (mView != null)
            mView.showSearchResultList(booksByTag.books);
        }
        @Override
        public void onCompleted() {
          LogUtils.i("complete");
          mView.complete();
        }
        @Override
        public void onError(Throwable e) {
          LogUtils.e("getSearchResultList:" + e.toString());
          if (mView != null)
            mView.showError();
        }
      });
  addSubscrebe(rxSubscription);
}

代码示例来源:origin: smuyyh/BookReader

@Override
public void getBookReviewList(final String sort, final String type, final String distillate, final int start, final int limit) {
  String key = StringUtils.creatAcacheKey("book-review-list", sort, type, distillate, start, limit);
  Observable<BookReviewList> fromNetWork = bookApi.getBookReviewList("all", sort, type, start + "", limit + "", distillate)
      .compose(RxUtil.<BookReviewList>rxCacheListHelper(key));
  //依次检查disk、network
  Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, BookReviewList.class), fromNetWork)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new Observer<BookReviewList>() {
        @Override
        public void onCompleted() {
          mView.complete();
        }
        @Override
        public void onError(Throwable e) {
          LogUtils.e("onError: "+e.toString());
          mView.showError();
        }
        @Override
        public void onNext(BookReviewList list) {
          LogUtils.d("onNext: get data finish");
          boolean isRefresh = start == 0 ? true : false;
          mView.showBookReviewList(list.reviews, isRefresh);
        }
      });
  addSubscrebe(rxSubscription);
}

代码示例来源:origin: smuyyh/BookReader

Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, CategoryList.class), fromNetWork)
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(new Observer<CategoryList>() {

代码示例来源:origin: smuyyh/BookReader

Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, BookLists.class), fromNetWork)
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(new Observer<BookLists>() {

代码示例来源:origin: smuyyh/BookReader

Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, BooksByTag.class), fromNetWork)
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(new Observer<BooksByTag>() {

代码示例来源:origin: smuyyh/BookReader

@Override
public void getRecommendList() {
  String key = StringUtils.creatAcacheKey("recommend-list", SettingManager.getInstance().getUserChooseSex());
  Observable<Recommend> fromNetWork = bookApi.getRecommend(SettingManager.getInstance().getUserChooseSex())
      .compose(RxUtil.<Recommend>rxCacheListHelper(key));
  //依次检查disk、network
  Subscription rxSubscription = Observable.concat(RxUtil.rxCreateDiskObservable(key, Recommend.class), fromNetWork)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new Observer<Recommend>() {
        @Override
        public void onNext(Recommend recommend) {
          if (recommend != null) {
            List<Recommend.RecommendBooks> list = recommend.books;
            if (list != null && !list.isEmpty() && mView != null) {
              mView.showRecommendList(list);
            }
          }
        }
        @Override
        public void onCompleted() {
          mView.complete();
        }
        @Override
        public void onError(Throwable e) {
          LogUtils.e("getRecommendList", e.toString());
          mView.showError();
        }
      });
  addSubscrebe(rxSubscription);
}

代码示例来源:origin: BaronZ88/MinimalistWeather

return Observable.concat(observableForGetWeatherFromDB, observableForGetWeatherFromNetWork)
    .filter(weather -> weather != null && !TextUtils.isEmpty(weather.getCityId()))
    .distinct(weather -> weather.getWeatherLive().getTime())

代码示例来源:origin: Netflix/EVCache

final List<EVCacheClient> fbClients = _pool.getEVCacheClientsForReadExcluding(client.getServerGroup());
if (fbClients != null && !fbClients.isEmpty()) {
  return Observable.concat(Observable.from(fbClients).map(
      fbClient -> getData(fbClients.indexOf(fbClient), fbClients.size(), fbClient, canonicalKey, tc, throwEx, throwExc, false, scheduler) //TODO : for the last one make sure to pass throwExc
      .doOnSuccess(fbData -> increment(fbClient.getServerGroupName(), _cacheName, "RETRY_" + ((fbData == null) ? "MISS" : "HIT")))

相关文章

Observable类方法