using Grpc.Core; using MessagePack; using System; using System.Threading.Tasks; namespace MagicOnion { /// /// Wrapped AsyncServerStreamingCall. /// public struct ServerStreamingResult : IDisposable { readonly AsyncServerStreamingCall inner; readonly IAsyncStreamReader responseStream; public ServerStreamingResult(AsyncServerStreamingCall inner, IAsyncStreamReader responseStream, MessagePackSerializerOptions serializerOptions) { this.inner = inner; this.responseStream = responseStream; } /// /// Async stream to read streaming responses. /// public IAsyncStreamReader ResponseStream { get { return responseStream; } } /// /// Asynchronous access to response headers. /// public Task ResponseHeadersAsync { get { return this.inner.ResponseHeadersAsync; } } /// /// Gets the call status if the call has already finished. /// Throws InvalidOperationException otherwise. /// public Status GetStatus() { return this.inner.GetStatus(); } /// /// Gets the call trailing metadata if the call has already finished. /// Throws InvalidOperationException otherwise. /// public Metadata GetTrailers() { return this.inner.GetTrailers(); } /// /// 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. /// /// /// Normally, there is no need for you to dispose the call unless you want to utilize the /// "Cancel" semantics of invoking Dispose. /// public void Dispose() { if (this.inner != null) { this.inner.Dispose(); } } } }