Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHubSearch example issue during lose of internet connection #7

Merged
merged 2 commits into from
Jul 25, 2017
Merged

GitHubSearch example issue during lose of internet connection #7

merged 2 commits into from
Jul 25, 2017

Conversation

Vkt0r
Copy link
Contributor

@Vkt0r Vkt0r commented Jul 11, 2017

@kzaher Excellent library !!!. I'm been reading a lot to be able to understand properly part of the stateful design of the library and it's real power.

During the search in the GithubPaginatedSearch if you start to make a search and then you disconnect your wifi then the system is going to retry every 0.1 seconds mainly because this line:

.retryWhen { $0.delay(1.0, scheduler: MainScheduler.instance) }

The only problem with that is that never is emitted the Observable<Error> to the State to properly update the UI bindings (the status label ). So pretty much if we change this behavior to after some attempts emit the Observable<Error> the UI can be updated and we can keep the consistency of keep trying make the request consistently.

.retryWhen { errorTrigger in
            return errorTrigger.flatMapWithIndex { (error, attempt) -> Observable<Int> in
                if attempt >= maxAttempts - 1 {
                    return Observable.error(error)
                }
                
                return Observable<Int>
                    .timer(Double(attempt + 1), scheduler: MainScheduler.instance).take(1)
            }

I have to say that this example is taken from the excellent RxSwift book. I think this is one the best uses I saw for the flatMapWithIndex operator.

- Reduce the height constraints to be able to show more repositories cells for the sake of the example.
- Replace the retryWhen to support a maximum number of attempts in the retry before launch the error and update the State to update the UI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants