diff options
Diffstat (limited to 'src/csharp/Grpc.Core/AsyncServerStreamingCall.cs')
-rw-r--r-- | src/csharp/Grpc.Core/AsyncServerStreamingCall.cs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/csharp/Grpc.Core/AsyncServerStreamingCall.cs b/src/csharp/Grpc.Core/AsyncServerStreamingCall.cs index 73b9614985..7a479b9a23 100644 --- a/src/csharp/Grpc.Core/AsyncServerStreamingCall.cs +++ b/src/csharp/Grpc.Core/AsyncServerStreamingCall.cs @@ -40,23 +40,15 @@ namespace Grpc.Core /// <summary> /// Return type for server streaming calls. /// </summary> - public sealed class AsyncServerStreamingCall<TResponse> - where TResponse : class + public sealed class AsyncServerStreamingCall<TResponse> : IDisposable { readonly IAsyncStreamReader<TResponse> responseStream; + readonly Action disposeAction; - public AsyncServerStreamingCall(IAsyncStreamReader<TResponse> responseStream) + public AsyncServerStreamingCall(IAsyncStreamReader<TResponse> responseStream, Action disposeAction) { this.responseStream = responseStream; - } - - /// <summary> - /// Reads the next response from ResponseStream - /// </summary> - /// <returns></returns> - public Task<TResponse> ReadNext() - { - return responseStream.ReadNext(); + this.disposeAction = disposeAction; } /// <summary> @@ -69,5 +61,16 @@ namespace Grpc.Core return responseStream; } } + + /// <summary> + /// Provides means to cleanup after the call. + /// If the call has already finished normally (response stream has been fully read), doesn't do anything. + /// Otherwise, requests cancellation of the call which should terminate all pending async operations associated with the call. + /// As a result, all resources being used by the call should be released eventually. + /// </summary> + public void Dispose() + { + disposeAction.Invoke(); + } } } |