grpc / grpc-swift

The Swift language implementation of gRPC.
Apache License 2.0
1.98k stars 407 forks source link

Access to `closeFuture` from `GRPCAsyncServerCallContext` #1954

Open wSedlacek opened 1 week ago

wSedlacek commented 1 week ago

Is your feature request related to a problem? Please describe it.

When attempting to write a server side stream there is no layer to obtain the closeFuture to add unsubscribe logic.

Describe the solution you'd like

I would love to simply have access to the closeFuture on the context, or a similar API to provide access to knowing when the client aborts the stream.

The AsyncServerCallContextProvider currently does not require anything with the closeFuture, even though the AsyncServerHandler which conforms to this protocol has the closeFuture passed into it's constructor.

Describe alternatives you've considered

I have looked into hacky work arounds to try to add my own extensions to force the closeFuture to be accessible, but it is buried behind too many layers of internal and private structs and classes.

I have looked into using the async only for unary calls and serve side streaming using the standard nio, but a provider cannot partially implement a service (so the proto would need to be split between two services)

Additional context

I am attempting to add an unsubscribe for a listener that triggers messages to be sent across the response stream.

glbrntt commented 1 week ago

The Task executing the RPC will be cancelled when the RPC closes, you should be able to hook into that to unsubscribe.