- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图将一个可完成链接到我的 Rx 链中,当我这样做时,链永远不会在 onError 或 onComplete 中完成。
当我单步执行代码时,会执行我的可完成代码。我什至可以添加日志记录并查看它登录它自己的 doOnComplete()
下面将记录“我已完成”,但不会进入错误或完成回调。
profileRepo.getLocalProfileIfAvailableElseRemote()
.flatMapCompletable { profile ->
userRoutingRepo.disableRule(profile.account_uid, userRoutingRule.id)
.doOnComplete {
Log.i("I COMPLETED", "I COMPLETED")
}
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeBy(
onError = { error ->
//do error
},
onComplete = {
//do success
}
).addTo(disposable)
profileRepo.getLocalProfileIfAvailableElseRemote()
.flatMap { profile ->
userRoutingRepo.disableRule(profile.account_uid, userRoutingRule.id)
.doOnComplete {
Log.i("I COMPLETED", "I COMPLETED")
}.andThen(Observable.just(true))
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeBy(
onError = { error ->
//do error
},
onNext = {
//do next
}
).addTo(disposable)
userRoutingService.disableRule(accountUid, ruleId)
是改造界面
profileRepo.getLocalProfileIfAvailableElseRemote()
.flatMapCompletable { profile ->
userRoutingRepo.disableRule(profile.account_uid, userRoutingRule.id)
.andThen(Completable.complete())
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeBy(
onError = { error ->
Log.i("TAG", "ERROR")
},
onComplete = {
Log.i("TAG", "COMPLETE")
}
).addTo(disposable)
override fun disableRule(accountUid: String, ruleId: String): Completable {
return activeStateToggler(userRoutingSourceApi.disableRule(accountUid, ruleId),
ruleId,
false)
}
override fun disableRule(accountUid: String, ruleId: String): Completable {
return userRoutingService.disableRule(accountUid, ruleId)
.doOnError { error ->
authenticationValidator.handleAuthenticationExceptions(error)
}
}
private fun activeStateToggler(completable: Completable,
ruleId: String,
stateOnSuccess: Boolean
): Completable {
return completable
.doOnSubscribe {
stateTogglingInProgress.add(ruleId)
}
.doOnComplete {
stateTogglingInProgress.remove(ruleId)
getLocalUserRule(ruleId)?.active = stateOnSuccess
stateTogglingInProgressPublishSubject.onNext(UserRoutingStateToggleSubjectType.Success)
}
.doOnError {
stateTogglingInProgress.remove(ruleId)
stateTogglingInProgressPublishSubject.onNext(UserRoutingStateToggleSubjectType.Error(
it))
}
}
最佳答案
这就是 flatMapCompletable 所做的:
Maps each element of the upstream Observable into CompletableSources,subscribes to them and waits until the upstream and allCompletableSources complete.
关于android - FlatMapCompletable 不会继续 Rx 链,但是带有 "andThen(Observable.just(true)"的可完成平面图可以工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55226848/
我期待 flatMapCompletable 会在 Completable 正常完成时调用给定的 Action。但是,它并不像我想的那样工作。这是一个简单的例子: PublishProcess
我有一个 Observable 可以发出项目并将它们上传到服务器。 代码如下: repository .getItems() .doOnComplete
我试图将一个可完成链接到我的 Rx 链中,当我这样做时,链永远不会在 onError 或 onComplete 中完成。 当我单步执行代码时,会执行我的可完成代码。我什至可以添加日志记录并查看它登录它
我是一名优秀的程序员,十分优秀!