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: Add Completable.takeUntil(Completable) operator #6079

Merged
merged 1 commit into from
Jul 11, 2018

Conversation

akarnokd
Copy link
Member

This PR adds the missing dedicated takeUntil operator to Completable.

image

Previously, the same effect could be achieved via the ambWith but there are two benefits of a dedicated operator:

  • easier to discover based on the takeUntil operator in other types
  • more direct implementation unlike ambWith which is built upon an N-ary amb operator with additional overhead.

There was a feature request in #3708 some time ago but apparently the issue got closed off after Single.takeUntil was implemented.

@akarnokd akarnokd added this to the 2.2 milestone Jul 10, 2018
@codecov
Copy link

codecov bot commented Jul 10, 2018

Codecov Report

Merging #6079 into 2.x will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #6079      +/-   ##
============================================
+ Coverage     98.23%   98.26%   +0.02%     
- Complexity     6189     6194       +5     
============================================
  Files           666      667       +1     
  Lines         44806    44856      +50     
  Branches       6206     6211       +5     
============================================
+ Hits          44014    44076      +62     
+ Misses          249      238      -11     
+ Partials        543      542       -1
Impacted Files Coverage Δ Complexity Δ
...s/completable/CompletableTakeUntilCompletable.java 100% <100%> (ø) 2 <2> (?)
src/main/java/io/reactivex/Completable.java 100% <100%> (ø) 116 <1> (+1) ⬆️
...l/operators/observable/ObservableFlatMapMaybe.java 88.88% <0%> (-4.58%) 2% <0%> (ø)
.../operators/mixed/FlowableConcatMapCompletable.java 97.43% <0%> (-2.57%) 2% <0%> (ø)
...perators/mixed/ObservableConcatMapCompletable.java 97.74% <0%> (-2.26%) 3% <0%> (ø)
...rnal/operators/flowable/FlowableFlatMapSingle.java 94.56% <0%> (-2.18%) 2% <0%> (ø)
...internal/operators/flowable/FlowableSwitchMap.java 95.75% <0%> (-1.42%) 3% <0%> (ø)
...ernal/operators/flowable/FlowableFromIterable.java 95.18% <0%> (-1.07%) 5% <0%> (ø)
...perators/observable/ObservableMergeWithSingle.java 99.06% <0%> (-0.94%) 2% <0%> (ø)
...operators/observable/ObservableMergeWithMaybe.java 99.1% <0%> (-0.9%) 2% <0%> (ø)
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fd76594...712a118. Read the comment docs.

}

void innerComplete() {
if (once.compareAndSet(false, true)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emit error if called more than once?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. It could legitimately lose a race against onComplete and we don't do it for any other operator either.

@CheckReturnValue
@Experimental
@SchedulerSupport(SchedulerSupport.NONE)
public final Completable takeUntil(CompletableSource other) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the bird has already flown with this one but the operator take refers to onNext events and we are more or less using it for all event types (take till terminates or the other thing terminates). I'm not suggesting a change perhaps a naming review for 3.x.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it more discoverable this way and besides, the main behavior of takeUntil is to stop the main source and complete the downstream, regardless of there could be items from the main source or not.

@akarnokd akarnokd merged commit 7e301d4 into ReactiveX:2.x Jul 11, 2018
@akarnokd akarnokd deleted the CompletableTakeUntil branch July 11, 2018 07:19
@kirk-l
Copy link

kirk-l commented Jul 15, 2018

Shouldn't there be a Completable.takeUntil(Publisher) operator, too? Single has overloads for both Publisher and CompletableSource.

@akarnokd
Copy link
Member Author

@sailorpsy PR welcome.

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.

5 participants