Skip to content

Commit 1de6137

Browse files
committed
fix: CompletableFuture -> abort(ex)
1 parent 69a35cc commit 1de6137

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

core/src/main/java/com/linecorp/armeria/common/stream/TimeoutStreamMessage.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.time.Duration;
2222
import java.util.concurrent.CompletableFuture;
2323
import java.util.concurrent.TimeUnit;
24+
import java.util.function.Consumer;
2425

2526
import org.reactivestreams.Subscriber;
2627
import org.reactivestreams.Subscription;
@@ -94,7 +95,7 @@ public CompletableFuture<Void> whenComplete() {
9495
public void subscribe(Subscriber<? super T> subscriber, EventExecutor executor,
9596
SubscriptionOption... options) {
9697
upstream.subscribe(new TimeoutSubscriber<>(subscriber, executor, timeoutDuration, timeoutMode,
97-
upstream.whenComplete()), executor, options);
98+
this::abort), executor, options);
9899
}
99100

100101
@Override
@@ -122,16 +123,16 @@ static final class TimeoutSubscriber<T> implements Runnable, Subscriber<T>, Subs
122123
private long lastEventTimeNanos;
123124
private boolean completed;
124125
private volatile boolean canceled;
125-
private final CompletableFuture<Void> completionFuture;
126+
private final Consumer<Throwable> upstreamAbort;
126127

127128
TimeoutSubscriber(Subscriber<? super T> downstream, EventExecutor executor, Duration timeoutDuration,
128-
StreamTimeoutMode timeoutMode, CompletableFuture<Void> completionFuture) {
129+
StreamTimeoutMode timeoutMode, Consumer<Throwable> upstreamAbort) {
129130
this.downstream = requireNonNull(downstream, "downstream");
130131
this.executor = requireNonNull(executor, "executor");
131132
this.timeoutDuration = requireNonNull(timeoutDuration, "timeoutDuration");
132133
timeoutNanos = timeoutDuration.toNanos();
133134
this.timeoutMode = requireNonNull(timeoutMode, "timeoutMode");
134-
this.completionFuture = requireNonNull(completionFuture, "completionFuture");
135+
this.upstreamAbort = requireNonNull(upstreamAbort, "upstreamAbort");
135136
}
136137

137138
private ScheduledFuture<?> scheduleTimeout(long delay) {
@@ -161,10 +162,8 @@ public void run() {
161162
final StreamTimeoutException ex = new StreamTimeoutException(
162163
String.format(TIMEOUT_MESSAGE, timeoutDuration.toMillis(), timeoutMode));
163164

164-
completionFuture.completeExceptionally(ex);
165165
downstream.onError(ex);
166-
assert subscription != null;
167-
subscription.cancel();
166+
upstreamAbort.accept(ex);
168167
}
169168

170169
@Override
@@ -205,7 +204,6 @@ public void onError(Throwable throwable) {
205204
}
206205
completed = true;
207206
cancelSchedule();
208-
completionFuture.completeExceptionally(throwable);
209207
downstream.onError(throwable);
210208
}
211209

@@ -216,7 +214,6 @@ public void onComplete() {
216214
}
217215
completed = true;
218216
cancelSchedule();
219-
completionFuture.complete(null);
220217
downstream.onComplete();
221218
}
222219

@@ -231,7 +228,6 @@ public void cancel() {
231228
canceled = true;
232229
cancelSchedule();
233230
assert subscription != null;
234-
completionFuture.completeExceptionally(CancelledSubscriptionException.get());
235231
subscription.cancel();
236232
}
237233
}

0 commit comments

Comments
 (0)