aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Core/Utils
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2015-05-18 14:28:22 -0700
committerGravatar Jan Tattermusch <jtattermusch@google.com>2015-05-20 10:55:54 -0700
commit7ca6179c666273c850e09f5ecbfc757d653c29ef (patch)
tree4e05e45b188d55415a6bf3f8b8dbf9197df291f5 /src/csharp/Grpc.Core/Utils
parent04ae923a52e8b2f61866a7e18e240fbb258969e9 (diff)
Make IAsyncReadStream use IAsyncEnumerator from Ix-Async
Diffstat (limited to 'src/csharp/Grpc.Core/Utils')
-rw-r--r--src/csharp/Grpc.Core/Utils/AsyncStreamExtensions.cs26
1 files changed, 8 insertions, 18 deletions
diff --git a/src/csharp/Grpc.Core/Utils/AsyncStreamExtensions.cs b/src/csharp/Grpc.Core/Utils/AsyncStreamExtensions.cs
index f915155f8a..a4f8989b30 100644
--- a/src/csharp/Grpc.Core/Utils/AsyncStreamExtensions.cs
+++ b/src/csharp/Grpc.Core/Utils/AsyncStreamExtensions.cs
@@ -49,14 +49,9 @@ namespace Grpc.Core.Utils
public static async Task ForEach<T>(this IAsyncStreamReader<T> streamReader, Func<T, Task> asyncAction)
where T : class
{
- while (true)
+ while (await streamReader.MoveNext())
{
- var elem = await streamReader.ReadNext();
- if (elem == null)
- {
- break;
- }
- await asyncAction(elem);
+ await asyncAction(streamReader.Current);
}
}
@@ -67,32 +62,27 @@ namespace Grpc.Core.Utils
where T : class
{
var result = new List<T>();
- while (true)
+ while (await streamReader.MoveNext())
{
- var elem = await streamReader.ReadNext();
- if (elem == null)
- {
- break;
- }
- result.Add(elem);
+ result.Add(streamReader.Current);
}
return result;
}
/// <summary>
/// Writes all elements from given enumerable to the stream.
- /// Closes the stream afterwards unless close = false.
+ /// Completes the stream afterwards unless close = false.
/// </summary>
- public static async Task WriteAll<T>(this IClientStreamWriter<T> streamWriter, IEnumerable<T> elements, bool close = true)
+ public static async Task WriteAll<T>(this IClientStreamWriter<T> streamWriter, IEnumerable<T> elements, bool complete = true)
where T : class
{
foreach (var element in elements)
{
await streamWriter.Write(element);
}
- if (close)
+ if (complete)
{
- await streamWriter.Close();
+ await streamWriter.Complete();
}
}