From ccd487b208d0e72a9a299f0461d7e009d061613d Mon Sep 17 00:00:00 2001 From: NepPure Date: Tue, 9 Nov 2021 11:11:24 +0800 Subject: [PATCH 1/5] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0c1b1c152..dc6daeed6 100644 --- a/README.md +++ b/README.md @@ -1467,10 +1467,10 @@ public class MyFirstService : ServiceBase, IMyFirstService var waitTask = Task.Run(async () => { // ForEachAsync(MoveNext, Current) can receive client streaming. - await stream.ForEachAsync(x => + while (await stream.MoveNext()) { - Logger.Debug($"Duplex Streaming Received:" + x); - }); + Logger.Debug($"Duplex Streaming Received:" + stream.Current); + } }); // WriteAsync is ServerStreaming. From 806e7b6534ecc85c2484dbd65f333aedf9e96826 Mon Sep 17 00:00:00 2001 From: NepPure Date: Tue, 9 Nov 2021 11:52:15 +0800 Subject: [PATCH 2/5] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dc6daeed6..a1d4ed74a 100644 --- a/README.md +++ b/README.md @@ -1528,8 +1528,9 @@ static async Task DuplexStreamRun(IMyFirstService client) var stream = await client.DuplexStreamingSampleAsync(); var count = 0; - await stream.ResponseStream.ForEachAsync(async x => + while (await stream.ResponseStream.MoveNext()) { + var x = stream.Current; Console.WriteLine("DuplexStream Response:" + x); await stream.RequestStream.WriteAsync(count++); @@ -1537,7 +1538,7 @@ static async Task DuplexStreamRun(IMyFirstService client) { await stream.RequestStream.CompleteAsync(); } - }); + } } ``` From e632cf83243f2277954dec625414af49a59f5f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E5=8E=9F=E5=B0=8F=E7=89=9B?= Date: Thu, 11 Nov 2021 14:51:50 +0800 Subject: [PATCH 3/5] await foreach --- README.md | 12 ++++++------ .../MagicOnion.Server.Tests.csproj | 2 +- tests/MagicOnion.Server.Tests/Tests/SimpleTest.cs | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a1d4ed74a..8f2bc917d 100644 --- a/README.md +++ b/README.md @@ -1432,10 +1432,10 @@ public class MyFirstService : ServiceBase, IMyFirstService var stream = GetClientStreamingContext(); // receive from client asynchronously - await stream.ForEachAsync(x => + await foreach (var x in stream.ReadAllAsync()) { Logger.Debug("Client Stream Received:" + x); - }); + } // StreamingContext.Result() for result value. return stream.Result("finished"); @@ -1467,9 +1467,9 @@ public class MyFirstService : ServiceBase, IMyFirstService var waitTask = Task.Run(async () => { // ForEachAsync(MoveNext, Current) can receive client streaming. - while (await stream.MoveNext()) + await foreach (var x in stream.ReadAllAsync()) { - Logger.Debug($"Duplex Streaming Received:" + stream.Current); + Logger.Debug($"Duplex Streaming Received:" + x); } }); @@ -1517,10 +1517,10 @@ static async Task ServerStreamRun(IMyFirstService client) { var stream = await client.ServerStreamingSampleAsync(10, 20, 3); - await stream.ResponseStream.ForEachAsync(x => + await foreach (var x in stream.ResponseStream.ReadAllAsync()) { Console.WriteLine("ServerStream Response:" + x); - }); + } } static async Task DuplexStreamRun(IMyFirstService client) diff --git a/tests/MagicOnion.Server.Tests/MagicOnion.Server.Tests.csproj b/tests/MagicOnion.Server.Tests/MagicOnion.Server.Tests.csproj index 0d717da04..889855d00 100644 --- a/tests/MagicOnion.Server.Tests/MagicOnion.Server.Tests.csproj +++ b/tests/MagicOnion.Server.Tests/MagicOnion.Server.Tests.csproj @@ -2,8 +2,8 @@ netcoreapp3.1 - false + 8.0 diff --git a/tests/MagicOnion.Server.Tests/Tests/SimpleTest.cs b/tests/MagicOnion.Server.Tests/Tests/SimpleTest.cs index d07ba7e46..aca328835 100644 --- a/tests/MagicOnion.Server.Tests/Tests/SimpleTest.cs +++ b/tests/MagicOnion.Server.Tests/Tests/SimpleTest.cs @@ -1,4 +1,4 @@ -using Grpc.Core; +using Grpc.Core; using MagicOnion.Client; using MagicOnion.Server; using System; @@ -45,10 +45,10 @@ public async Task> ClientStreaming1Task() var streaming = GetClientStreamingContext(); var list = new List(); - await streaming.ForEachAsync(x => + await foreach (var x in streaming.ReadAllAsync()) { list.Add(x); - }); + } return streaming.Result("finished:" + string.Join(", ", list)); } @@ -65,9 +65,9 @@ public async Task> DuplexStreaming1Task() var l = new List(); - while (await stream.MoveNext()) + await foreach (var x in stream.ReadAllAsync()) { - l.Add(stream.Current); + l.Add(x); await stream.WriteAsync(string.Join(", ", l)); } @@ -138,7 +138,7 @@ public async Task Unary() r.Should().Be(30); var r0 = await client.Unary1Task(1000, 2000); - var r2 = await r0; + var r2 = await r0; r2.Should().Be(3000); } From 7bb07ff27da4ad397959a64a8d364050e9a52b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E5=8E=9F=E5=B0=8F=E7=89=9B?= Date: Thu, 11 Nov 2021 15:04:49 +0800 Subject: [PATCH 4/5] default --- tests/MagicOnion.Server.Tests/MagicOnion.Server.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/MagicOnion.Server.Tests/MagicOnion.Server.Tests.csproj b/tests/MagicOnion.Server.Tests/MagicOnion.Server.Tests.csproj index e175fc734..fa6cfe5a6 100644 --- a/tests/MagicOnion.Server.Tests/MagicOnion.Server.Tests.csproj +++ b/tests/MagicOnion.Server.Tests/MagicOnion.Server.Tests.csproj @@ -2,7 +2,7 @@ net6.0 - + default false From 79ca75ea661645c848d74a3ec66f296d2c4cc748 Mon Sep 17 00:00:00 2001 From: NepPure Date: Thu, 11 Nov 2021 15:20:53 +0800 Subject: [PATCH 5/5] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 8f2bc917d..f237f88c4 100644 --- a/README.md +++ b/README.md @@ -1528,9 +1528,8 @@ static async Task DuplexStreamRun(IMyFirstService client) var stream = await client.DuplexStreamingSampleAsync(); var count = 0; - while (await stream.ResponseStream.MoveNext()) + await foreach (var x in stream.ResponseStream.ReadAllAsync()) { - var x = stream.Current; Console.WriteLine("DuplexStream Response:" + x); await stream.RequestStream.WriteAsync(count++);