diff options
Diffstat (limited to 'src/csharp/Grpc.Examples/MathExamples.cs')
-rw-r--r-- | src/csharp/Grpc.Examples/MathExamples.cs | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/src/csharp/Grpc.Examples/MathExamples.cs b/src/csharp/Grpc.Examples/MathExamples.cs index 032372b2a1..dba5a7736c 100644 --- a/src/csharp/Grpc.Examples/MathExamples.cs +++ b/src/csharp/Grpc.Examples/MathExamples.cs @@ -61,9 +61,8 @@ namespace math public static async Task FibExample(MathGrpc.IMathServiceClient stub) { - var recorder = new RecordingObserver<Num>(); - stub.Fib(new FibArgs.Builder { Limit = 5 }.Build(), recorder); - List<Num> result = await recorder.ToList(); + var call = stub.Fib(new FibArgs.Builder { Limit = 5 }.Build()); + List<Num> result = await call.ResponseStream.ToList(); Console.WriteLine("Fib Result: " + string.Join("|", result)); } @@ -76,9 +75,9 @@ namespace math new Num.Builder { Num_ = 3 }.Build() }; - var clientStreamingResult = stub.Sum(); - numbers.Subscribe(clientStreamingResult.Inputs); - Console.WriteLine("Sum Result: " + await clientStreamingResult.Task); + var call = stub.Sum(); + await call.RequestStream.WriteAll(numbers); + Console.WriteLine("Sum Result: " + await call.Result); } public static async Task DivManyExample(MathGrpc.IMathServiceClient stub) @@ -89,12 +88,9 @@ namespace math new DivArgs.Builder { Dividend = 100, Divisor = 21 }.Build(), new DivArgs.Builder { Dividend = 7, Divisor = 2 }.Build() }; - - var recorder = new RecordingObserver<DivReply>(); - var inputs = stub.DivMany(recorder); - divArgsList.Subscribe(inputs); - var result = await recorder.ToList(); - Console.WriteLine("DivMany Result: " + string.Join("|", result)); + var call = stub.DivMany(); + await call.RequestStream.WriteAll(divArgsList); + Console.WriteLine("DivMany Result: " + string.Join("|", await call.ResponseStream.ToList())); } public static async Task DependendRequestsExample(MathGrpc.IMathServiceClient stub) @@ -106,9 +102,9 @@ namespace math new Num.Builder { Num_ = 3 }.Build() }; - var clientStreamingResult = stub.Sum(); - numbers.Subscribe(clientStreamingResult.Inputs); - Num sum = await clientStreamingResult.Task; + var sumCall = stub.Sum(); + await sumCall.RequestStream.WriteAll(numbers); + Num sum = await sumCall.Result; DivReply result = await stub.DivAsync(new DivArgs.Builder { Dividend = sum.Num_, Divisor = numbers.Count }.Build()); Console.WriteLine("Avg Result: " + result); |