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

Side by Side Diff: third_party/grpc/src/csharp/Grpc.Core/AsyncClientStreamingCall.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.Runtime.CompilerServices;
36 using System.Threading.Tasks;
37
38 namespace Grpc.Core
39 {
40 /// <summary>
41 /// Return type for client streaming calls.
42 /// </summary>
43 /// <typeparam name="TRequest">Request message type for this call.</typepara m>
44 /// <typeparam name="TResponse">Response message type for this call.</typepa ram>
45 public sealed class AsyncClientStreamingCall<TRequest, TResponse> : IDisposa ble
46 {
47 readonly IClientStreamWriter<TRequest> requestStream;
48 readonly Task<TResponse> responseAsync;
49 readonly Task<Metadata> responseHeadersAsync;
50 readonly Func<Status> getStatusFunc;
51 readonly Func<Metadata> getTrailersFunc;
52 readonly Action disposeAction;
53
54 internal AsyncClientStreamingCall(IClientStreamWriter<TRequest> requestS tream, Task<TResponse> responseAsync, Task<Metadata> responseHeadersAsync, Func< Status> getStatusFunc, Func<Metadata> getTrailersFunc, Action disposeAction)
55 {
56 this.requestStream = requestStream;
57 this.responseAsync = responseAsync;
58 this.responseHeadersAsync = responseHeadersAsync;
59 this.getStatusFunc = getStatusFunc;
60 this.getTrailersFunc = getTrailersFunc;
61 this.disposeAction = disposeAction;
62 }
63
64 /// <summary>
65 /// Asynchronous call result.
66 /// </summary>
67 public Task<TResponse> ResponseAsync
68 {
69 get
70 {
71 return this.responseAsync;
72 }
73 }
74
75 /// <summary>
76 /// Asynchronous access to response headers.
77 /// </summary>
78 public Task<Metadata> ResponseHeadersAsync
79 {
80 get
81 {
82 return this.responseHeadersAsync;
83 }
84 }
85
86 /// <summary>
87 /// Async stream to send streaming requests.
88 /// </summary>
89 public IClientStreamWriter<TRequest> RequestStream
90 {
91 get
92 {
93 return requestStream;
94 }
95 }
96
97 /// <summary>
98 /// Allows awaiting this object directly.
99 /// </summary>
100 /// <returns></returns>
101 public TaskAwaiter<TResponse> GetAwaiter()
102 {
103 return responseAsync.GetAwaiter();
104 }
105
106 /// <summary>
107 /// Gets the call status if the call has already finished.
108 /// Throws InvalidOperationException otherwise.
109 /// </summary>
110 public Status GetStatus()
111 {
112 return getStatusFunc();
113 }
114
115 /// <summary>
116 /// Gets the call trailing metadata if the call has already finished.
117 /// Throws InvalidOperationException otherwise.
118 /// </summary>
119 public Metadata GetTrailers()
120 {
121 return getTrailersFunc();
122 }
123
124 /// <summary>
125 /// Provides means to cleanup after the call.
126 /// If the call has already finished normally (request stream has been c ompleted and call result has been received), doesn't do anything.
127 /// Otherwise, requests cancellation of the call which should terminate all pending async operations associated with the call.
128 /// As a result, all resources being used by the call should be released eventually.
129 /// </summary>
130 public void Dispose()
131 {
132 disposeAction.Invoke();
133 }
134 }
135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698