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

[#10079] Propagate pubsub req cancellation #10080

Merged
merged 1 commit into from
Jun 27, 2023
Merged
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 @@ -51,11 +51,13 @@ public Flux<S> request(D demand) {
final Identifier id = identifierFactory.get();
final SubChannel<SupplyMessage<S>> supplyChannel = supplyRouter.apply(id);
final SubConsumer<SupplyMessage<S>> subConsumer = new LongTermSubConsumer<>(sink, id, subscriptionRef);
subscriptionRef.set(supplyChannel.subscribe(subConsumer));
final Subscription subscription = supplyChannel.subscribe(subConsumer);
subscriptionRef.set(subscription);

demandRouter.apply(id).publish(DemandMessage.ok(id, demand));

return sink.asFlux();
return sink.asFlux()
.doFinally(e -> subscription.unsubscribe());
}

static class LongTermSubConsumer<S> implements SubConsumer<SupplyMessage<S>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ public Mono<S> request(D demand) {
final Identifier id = identifierFactory.get();
final SubChannel<SupplyMessage<S>> supplyChannel = supplyRouter.apply(id);
final SubConsumer<SupplyMessage<S>> subConsumer = new ShortTermSubConsumer<>(sink, id, subscriptionRef);
subscriptionRef.set(supplyChannel.subscribe(subConsumer));
final Subscription subscription = supplyChannel.subscribe(subConsumer);
subscriptionRef.set(subscription);

demandRouter.apply(id).publish(DemandMessage.ok(id, demand));

return sink.asMono().timeout(this.options.getRequestTimeout());
return sink.asMono()
.doFinally(e -> subscription.unsubscribe())
.timeout(this.options.getRequestTimeout());
}

static class ShortTermSubConsumer<S> implements SubConsumer<SupplyMessage<S>> {
Expand Down