Clean close of connections for GRPC clients

Hi, I have started a new project using the GRPC clients, current nuget 21.2.0 on net5.0.
Before I used the tcp client, and handling the events and being able to close the connection when shutting down.
I can’t find anything (even on the docs for the GRPC clients) but a Dispose method on the EventStoreClient and the StreamSubscrption returned upon a SubscribeToStreamAsync()
I’m connecting at the begining of the my background service with a singleton like

_client = new EventStoreClient(EventStoreClientSettings.Create(_settings.ConnectionString));

Then I subscribe to my stream

_subscription = await _client.SubscribeToStreamAsync(
            new StreamPosition(position),
            async (_, @event, c) =>
                await _eventsProcessor.Process(@event, c);
            cancellationToken: cancellationToken);

When my worker receives the shutdown signal I want to stop listening for events in a clean way.
What should I do?
Call Dispose for the _subscription and then for the _client()? Just for the client?

You should dispose both

1 Like