Error Handling - .retryWhen produces an anomaly

Hello,
When I used a code for Error Handling chapter example I get error like that:

== retrying after 0 seconds ==
== retrying after 1 seconds ==
== retrying after 2 seconds ==
⚠️ Reentrancy anomaly was detected.
  > Debugging: To debug this issue you can set a breakpoint in /Users/.../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.

⚠️ Reentrancy anomaly was detected.
  > Debugging: To debug this issue you can set a breakpoint in /Users/.../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.

Errored:  The CREATE operation couldn’t be completed.

My exact code:

MyService().setSomeData("xxx")
            .retryWhen { e in
                return e.enumerated().flatMap { attempt, error -> Observable<Int> in
                    if attempt >= maxAttempts - 1 {
                        return Observable.error(error)
                    }
                    print("== retrying after \(attempt) seconds ==")
                    return Observable<Int>.timer(Double(attempt + 1),
                                                 scheduler: MainScheduler.instance).take(1)
                }
            }
            .subscribe(onSuccess: { _ in
                print("SUCCESS")
            }, onError: { error in
                print("Errored: ", error.localizedDescription)
            })
            .disposed(by: bag)

@destroplayer Do you still have issues with this?

Yes. I guess SwiftExt has taken a better approach to this but I didn’t get a closer look at it.

This topic was automatically closed after 166 days. New replies are no longer allowed.