我正在尝试在concatMap
内部实现,RxSwift
但是当我尝试为内部的可观察对象设置一个新值时,concatMap
我收到了这个错误:
Reentrancy anomaly was detected.
> Debugging: To debug this issue you can set a breakpoint in /Users/SuperUser/repos/RxObserver/Pods/RxSwift/RxSwift/Rx.swift:96 and observe the call stack.
> Problem: This behavior is breaking the observable sequence grammar. `next (error | completed)?`
This behavior breaks the grammar because there is overlapping between sequence events.
Observable sequence is trying to send an event before sending of previous event has finished.
> Interpretation: This could mean that there is some kind of unexpected cyclic dependency in your code,
or that the system is not behaving in the expected way.
> Remedy: If this is the expected behavior this message can be suppressed by adding `.observeOn(MainScheduler.asyncInstance)`
or by enqueuing sequence events in some other way.
这是我的代码:
public let myNumbers = BehaviorRelay<String>(value: "")
override func viewDidLoad() {
super.viewDidLoad()
processNumbers()
myNumbers.accept("one")
myNumbers.accept("two")
}
func processNumbers() {
Observable.of(myNumbers).concatMap{ $0
}.subscribe(onNext:{
print($0)
if $0 == "one" || $0 == "two"{
self.myNumbers.accept("YEAH!")
}
}).disposed(by: disposeBag)
}
你们中的任何人都知道我为什么会收到此错误或如何更改我的实现以避免收到此错误/警告?
我会非常感谢你的帮助。