Retrofit & RxJava multiple requests complete

后端 未结 4 2248
盖世英雄少女心
盖世英雄少女心 2021-02-14 10:25

I need to do:

  1. Request 2 lists of news from different websites
  2. Combine results from requests
  3. Sort items by date
  4. Get 10 newest news
  5. <
4条回答
  •  梦毁少年i
    2021-02-14 10:48

    If you don't want to do something specific with the combined results, then merge() is enough:

    Observable regionalNews = ...;
    Observable nationalNews = ...;
    
    Observable
    .merge(regionalNews, nationalNews)
    .ignoreElements()
    .observeOn(AndroidSchedulers.mainThread())
    .doOnComplete(() -> { /* show alert */ })
    .subscribe()
    

提交回复
热议问题