Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public void onError(Throwable t) {
return;
}
once = true;
main.onError(t);
//cancel main.main, and ensure that if this happens early an empty Subscription is passed down
main.cancelMainAndError(t);
}

@Override
Expand Down Expand Up @@ -183,6 +184,26 @@ public void request(long n) {
s.request(n);
}

void cancelMainAndError(Throwable t) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note that this is virtually identical to the cancelMainAndComplete method below, except signaling error vs. complete

Subscription s = main;
if (s != Operators.cancelledSubscription()) {
s = MAIN.getAndSet(this, Operators.cancelledSubscription());
if (s != null && s != Operators.cancelledSubscription()) {
s.cancel();
}

if (s == null) {
// this indicates the Other errored early, even before `main` was set.
// let's pass an empty Subscription down and error immediately
Operators.error(actual, t);
}
else {
// if s wasn't null then Main Subscription was set and actual.onSubscribe already called
actual.onError(t);
}
}
}

void cancelMainAndComplete() {
Subscription s = main;
if (s != Operators.cancelledSubscription()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2022 VMware Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2016-2026 VMware Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -201,13 +201,15 @@ public void otherSignalsError() {

Flux<Object> other =
Flux.error(new RuntimeException("forced " + "failure"))
.delaySubscription(Duration.ofMillis(1))
.doOnCancel(() -> otherCancelled.set(true));
Flux.range(1, 10)
Flux.<Integer>never()
.doOnCancel(() -> mainCancelled.set(true))
.takeUntilOther(other)
.subscribe(ts);

ts.assertNoValues()
ts.await()
.assertNoValues()
.assertNotComplete()
.assertError(RuntimeException.class)
.assertErrorMessage("forced failure");
Expand Down
Loading