【问题标题】:Sequential RxJava network calls顺序 RxJava 网络调用
【发布时间】:2018-06-12 16:12:33
【问题描述】:

我想进行两次调用,一次调用 github repos 列表,第二次调用每个 repo 上的提交,并希望将它们保存在一起。

在第二次调用中,我需要父 pojo 的实例,以便我可以将子响应添加到它。

即保存:Gitrepo

Gitrepo{
var name:String,
var commit:Commit //<-this is fetched in second call
}

当前代码:

                        networkModule.getRepos()
                        .flatMap { itemList ->
                            Observable.fromIterable(itemList)
                        }
                        .concatMapEager { item -> networkModule.getCommits(item.name!!)
                                .onErrorResumeNext(Observable.empty()) }
                        .subscribe(
                                {
                                //problem is here I get only Commit pojo, 
                                //and have no access to Gitrepo, I'd like to do: 

                                //gitrepo.commit = it 
                                //db.save(gitrepo)
                                },
                                {
                                    utilModule.logI("error response" + it.message)
                                }
                        )

【问题讨论】:

    标签: android retrofit2 rx-java2 rx-android


    【解决方案1】:

    我认为 GitRepo 是一个类

    试试这个:

    networkModule.getRepos()
    .flatMap { itemList -> 
         networkModule.getCommits(itemList.name!!).map{
             item -> GitRepo(
         name = itemList.name,
         commit = item
               ).onErrorResumeNext(Observable.empty())
        }
    }
    .subscribe(
        {
            /*do what you want*/
        },
        {
            utilModule.logI("error response" + it.message)
        }
     )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多