顺序 RxJava 网络调用
Sequential RxJava network calls
我想进行两次调用,一次调用 github 个回购列表,第二次调用每个回购的提交,并希望将它们保存在一起。
在第二次调用中,我需要父 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)
}
)
我想 GitRepo 是一个 class
试试这个:
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)
}
)
我想进行两次调用,一次调用 github 个回购列表,第二次调用每个回购的提交,并希望将它们保存在一起。
在第二次调用中,我需要父 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)
}
)
我想 GitRepo 是一个 class
试试这个:
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)
}
)