Skip to content

Commit

Permalink
Merge pull request Cysharp#468 from NepPure/patch-1
Browse files Browse the repository at this point in the history
Update smple code "await foreach"
  • Loading branch information
mayuki authored Nov 11, 2021
2 parents 3efdb1b + 79ca75e commit ef515a5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1432,10 +1432,10 @@ public class MyFirstService : ServiceBase<IMyFirstService>, IMyFirstService
var stream = GetClientStreamingContext<int, string>();

// 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");
Expand Down Expand Up @@ -1467,10 +1467,10 @@ public class MyFirstService : ServiceBase<IMyFirstService>, IMyFirstService
var waitTask = Task.Run(async () =>
{
// ForEachAsync(MoveNext, Current) can receive client streaming.
await stream.ForEachAsync(x =>
await foreach (var x in stream.ReadAllAsync())
{
Logger.Debug($"Duplex Streaming Received:" + x);
});
}
});

// WriteAsync is ServerStreaming.
Expand Down Expand Up @@ -1517,18 +1517,18 @@ 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)
{
var stream = await client.DuplexStreamingSampleAsync();

var count = 0;
await stream.ResponseStream.ForEachAsync(async x =>
await foreach (var x in stream.ResponseStream.ReadAllAsync())
{
Console.WriteLine("DuplexStream Response:" + x);

Expand All @@ -1537,7 +1537,7 @@ static async Task DuplexStreamRun(IMyFirstService client)
{
await stream.RequestStream.CompleteAsync();
}
});
}
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>

<LangVersion>default</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
12 changes: 6 additions & 6 deletions tests/MagicOnion.Server.Tests/Tests/SimpleTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Grpc.Core;
using Grpc.Core;
using MagicOnion.Client;
using MagicOnion.Server;
using System;
Expand Down Expand Up @@ -45,10 +45,10 @@ public async Task<ClientStreamingResult<int, string>> ClientStreaming1Task()
var streaming = GetClientStreamingContext<int, string>();

var list = new List<int>();
await streaming.ForEachAsync(x =>
await foreach (var x in streaming.ReadAllAsync())
{
list.Add(x);
});
}

return streaming.Result("finished:" + string.Join(", ", list));
}
Expand All @@ -65,9 +65,9 @@ public async Task<DuplexStreamingResult<int, string>> DuplexStreaming1Task()

var l = new List<int>();

while (await stream.MoveNext())
await foreach (var x in stream.ReadAllAsync())
{
l.Add(stream.Current);
l.Add(x);
await stream.WriteAsync(string.Join(", ", l));
}

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit ef515a5

Please sign in to comment.