Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: third_party/grpc/src/csharp/Grpc.Core/AsyncServerStreamingCall.cs

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #region Copyright notice and license
2
3 // Copyright 2015, Google Inc.
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
15 // distribution.
16 // * Neither the name of Google Inc. nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 #endregion
33
34 using System;
35 using System.Threading.Tasks;
36
37 namespace Grpc.Core
38 {
39 /// <summary>
40 /// Return type for server streaming calls.
41 /// </summary>
42 /// <typeparam name="TResponse">Response message type for this call.</typepa ram>
43 public sealed class AsyncServerStreamingCall<TResponse> : IDisposable
44 {
45 readonly IAsyncStreamReader<TResponse> responseStream;
46 readonly Task<Metadata> responseHeadersAsync;
47 readonly Func<Status> getStatusFunc;
48 readonly Func<Metadata> getTrailersFunc;
49 readonly Action disposeAction;
50
51 internal AsyncServerStreamingCall(IAsyncStreamReader<TResponse> response Stream, Task<Metadata> responseHeadersAsync, Func<Status> getStatusFunc, Func<Me tadata> getTrailersFunc, Action disposeAction)
52 {
53 this.responseStream = responseStream;
54 this.responseHeadersAsync = responseHeadersAsync;
55 this.getStatusFunc = getStatusFunc;
56 this.getTrailersFunc = getTrailersFunc;
57 this.disposeAction = disposeAction;
58 }
59
60 /// <summary>
61 /// Async stream to read streaming responses.
62 /// </summary>
63 public IAsyncStreamReader<TResponse> ResponseStream
64 {
65 get
66 {
67 return responseStream;
68 }
69 }
70
71 /// <summary>
72 /// Asynchronous access to response headers.
73 /// </summary>
74 public Task<Metadata> ResponseHeadersAsync
75 {
76 get
77 {
78 return this.responseHeadersAsync;
79 }
80 }
81
82 /// <summary>
83 /// Gets the call status if the call has already finished.
84 /// Throws InvalidOperationException otherwise.
85 /// </summary>
86 public Status GetStatus()
87 {
88 return getStatusFunc();
89 }
90
91 /// <summary>
92 /// Gets the call trailing metadata if the call has already finished.
93 /// Throws InvalidOperationException otherwise.
94 /// </summary>
95 public Metadata GetTrailers()
96 {
97 return getTrailersFunc();
98 }
99
100 /// <summary>
101 /// Provides means to cleanup after the call.
102 /// If the call has already finished normally (response stream has been fully read), doesn't do anything.
103 /// Otherwise, requests cancellation of the call which should terminate all pending async operations associated with the call.
104 /// As a result, all resources being used by the call should be released eventually.
105 /// </summary>
106 public void Dispose()
107 {
108 disposeAction.Invoke();
109 }
110 }
111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698