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

2.x: A.flatMapB to eagerly check for cancellations before subscribing #4992

Merged
merged 1 commit into from
Jan 16, 2017

Conversation

akarnokd
Copy link
Member

The flatMap implementations always subscribed to the generated inner source even if there was an asynchronous cancel while the function was running. With typical functions, there is only a really tiny window inside function but some users tend to block/sleep in the function and when that returns, the flatMap operator is already cancelled.

If the generated inner source emitted an error disregarding its own cancellation signal (the error() operators do this), those errors end up in the RxJavaPlugins.onError and crash the app (on Android).

This PR adjusts the flatMap implementations to check for the disposed/cancelled state before subscribing to the inner source. For Observable and Flowable, this has practically no extra overhead as the add/remove already checks for the terminal state and can return a boolean for it. The rest require an explicit isDisposed() check.

@akarnokd akarnokd added this to the 2.0 backlog milestone Jan 13, 2017
@codecov-io
Copy link

Current coverage is 95.58% (diff: 100%)

Merging #4992 into 2.x will increase coverage by 0.05%

@@                2.x      #4992   diff @@
==========================================
  Files           592        592          
  Lines         37969      37974     +5   
  Methods           0          0          
  Messages          0          0          
  Branches       5752       5768    +16   
==========================================
+ Hits          36273      36298    +25   
+ Misses          741        725    -16   
+ Partials        955        951     -4   

Powered by Codecov. Last update cd45675...02ab095

@akarnokd akarnokd merged commit 2e6f94c into ReactiveX:2.x Jan 16, 2017
@akarnokd akarnokd deleted the FlatMapCheckCancelledState branch January 16, 2017 10:13
@JakeWharton
Copy link
Contributor

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants