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

Publisher#takeUntil cancel before terminate #2413

Merged
merged 3 commits into from
Nov 8, 2022

Conversation

Scottmitch
Copy link
Member

Motivation:
Publisher#takeUntil will terminate downstream before cancelling upstream. There are some sources (e.g. NettyChannelPublisher) that allow resubscribe in a sequential fashion, but in order for this to work cancellation must be first.

Modifications:

  • Switch ordering in TakeUtil to cancel before terminate
  • Add TestResubscribePublisher utility that wraps TestPublisher which allows for sequential resbuscribes.

Motivation:
Publisher#takeUntil will terminate downstream before cancelling upstream.
There are some sources (e.g. NettyChannelPublisher) that allow resubscribe
in a sequential fashion, but in order for this to work cancellation must be
first.

Modifications:
- Switch ordering in TakeUtil to cancel before terminate
- Add TestResubscribePublisher utility that wraps TestPublisher which allows
  for sequential resbuscribes.
* @return A {@link Publisher} that only emits the items till {@code until} {@link Completable} is completed.
* @see <a href="https://reactivex.io/documentation/operators/takeuntil.html">ReactiveX takeUntil operator.</a>
*/
public final Publisher<T> takeUntil(Supplier<? extends Completable> untilSupplier) {
Copy link
Member Author

@Scottmitch Scottmitch Nov 7, 2022

Choose a reason for hiding this comment

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

@idelpivnitskiy - I know we have had discussion about providing Supplier vs using defer(() -> ..) in the past. We could continue to assume folks know they should use defer(() -> ..) but in this case it was missed in internal usage and when Completable terminates the Publisher is also terminated, which may trigger re-subscribe... so this state is directly related to termination.

Copy link
Member Author

Choose a reason for hiding this comment

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

discussed offline ... Publisher.defer(() -> ..) can be used as a building block in this case. we can add followup docs/examples to clarify making operators that may retain state re-subscribe safe.

@Scottmitch
Copy link
Member Author

test failure attributed to #2414

@Scottmitch
Copy link
Member Author

merging as no API changes and discussed offline

@Scottmitch Scottmitch merged commit 7de32fc into apple:main Nov 8, 2022
@Scottmitch Scottmitch deleted the take_until_resubscribe branch November 8, 2022 23:33
Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

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

Late LGTM, thanks!

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.

2 participants