aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/GrpcCore/Internal/StreamingInputObserver.cs
blob: c5de979351a14058405d685914a81d41d2a733d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using Google.GRPC.Core.Internal;

namespace Google.GRPC.Core.Internal
{
    internal class StreamingInputObserver<TWrite, TRead> : IObserver<TWrite>
	{
        readonly AsyncCall<TWrite, TRead> call;

        public StreamingInputObserver(AsyncCall<TWrite, TRead> call)
		{
            this.call = call;
		}

		public void OnCompleted()
		{
            // TODO: how bad is the Wait here?
            call.WritesCompletedAsync().Wait();
		}

		public void OnError(Exception error)
		{
			throw new InvalidOperationException("This should never be called.");
		}

		public void OnNext(TWrite value)
		{
            // TODO: how bad is the Wait here?
            call.WriteAsync(value).Wait();
		}
	}
}