Remove System.Interactive.Async dependency

pull/19059/head
James Newton-King 6 years ago
parent cdaef92839
commit a0aa16a078
No known key found for this signature in database
GPG Key ID: A66B2F456BF5526
  1. 4
      src/csharp/Grpc.Core.Api/Grpc.Core.Api.csproj
  2. 22
      src/csharp/Grpc.Core.Api/IAsyncStreamReader.cs
  3. 6
      src/csharp/Grpc.Core/Grpc.Core.csproj
  4. 53
      src/csharp/Grpc.Core/Utils/AsyncStreamExtensions.cs
  5. 3
      src/csharp/Grpc.Reflection.Tests/ReflectionClientServerTest.cs

@ -25,10 +25,6 @@
<Import Project="..\Grpc.Core\SourceLink.csproj.include" />
<ItemGroup>
<PackageReference Include="System.Interactive.Async" Version="3.2.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Memory" Version="4.5.2" />
</ItemGroup>

@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license
// Copyright 2015 gRPC authors.
//
@ -16,10 +16,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Grpc.Core
@ -50,7 +47,20 @@ namespace Grpc.Core
/// </para>
/// </summary>
/// <typeparam name="T">The message type.</typeparam>
public interface IAsyncStreamReader<T> : IAsyncEnumerator<T>
public interface IAsyncStreamReader<T>
{
/// <summary>
/// Gets the current element in the iteration.
/// </summary>
T Current { get; }
/// <summary>
/// Advances the reader to the next element in the sequence, returning the result asynchronously.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to cancel the operation.</param>
/// <returns>
/// Task containing the result of the operation: true if the reader was successfully advanced
/// to the next element; false if the reader has passed the end of the sequence.</returns>
Task<bool> MoveNext(CancellationToken cancellationToken);
}
}

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="Common.csproj.include" />
@ -98,10 +98,6 @@
<ProjectReference Include="../Grpc.Core.Api/Grpc.Core.Api.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Interactive.Async" Version="3.2.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />

@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Grpc.Core.Utils
@ -27,12 +28,41 @@ namespace Grpc.Core.Utils
/// </summary>
public static class AsyncStreamExtensions
{
/// <summary>
/// Advances the stream reader to the next element in the sequence, returning the result asynchronously.
/// </summary>
/// <typeparam name="T">The message type.</typeparam>
/// <param name="streamReader">The stream reader.</param>
/// <returns>
/// Task containing the result of the operation: true if the reader was successfully advanced
/// to the next element; false if the reader has passed the end of the sequence.
/// </returns>
public static Task<bool> MoveNext<T>(this IAsyncStreamReader<T> streamReader)
where T : class
{
if (streamReader == null)
{
throw new ArgumentNullException(nameof(streamReader));
}
return streamReader.MoveNext(CancellationToken.None);
}
/// <summary>
/// Reads the entire stream and executes an async action for each element.
/// </summary>
public static async Task ForEachAsync<T>(this IAsyncStreamReader<T> streamReader, Func<T, Task> asyncAction)
where T : class
{
if (streamReader == null)
{
throw new ArgumentNullException(nameof(streamReader));
}
if (asyncAction == null)
{
throw new ArgumentNullException(nameof(asyncAction));
}
while (await streamReader.MoveNext().ConfigureAwait(false))
{
await asyncAction(streamReader.Current).ConfigureAwait(false);
@ -45,6 +75,11 @@ namespace Grpc.Core.Utils
public static async Task<List<T>> ToListAsync<T>(this IAsyncStreamReader<T> streamReader)
where T : class
{
if (streamReader == null)
{
throw new ArgumentNullException(nameof(streamReader));
}
var result = new List<T>();
while (await streamReader.MoveNext().ConfigureAwait(false))
{
@ -60,6 +95,15 @@ namespace Grpc.Core.Utils
public static async Task WriteAllAsync<T>(this IClientStreamWriter<T> streamWriter, IEnumerable<T> elements, bool complete = true)
where T : class
{
if (streamWriter == null)
{
throw new ArgumentNullException(nameof(streamWriter));
}
if (elements == null)
{
throw new ArgumentNullException(nameof(elements));
}
foreach (var element in elements)
{
await streamWriter.WriteAsync(element).ConfigureAwait(false);
@ -76,6 +120,15 @@ namespace Grpc.Core.Utils
public static async Task WriteAllAsync<T>(this IServerStreamWriter<T> streamWriter, IEnumerable<T> elements)
where T : class
{
if (streamWriter == null)
{
throw new ArgumentNullException(nameof(streamWriter));
}
if (elements == null)
{
throw new ArgumentNullException(nameof(elements));
}
foreach (var element in elements)
{
await streamWriter.WriteAsync(element).ConfigureAwait(false);

@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
@ -21,6 +21,7 @@ using System.Text;
using System.Threading.Tasks;
using Grpc.Core;
using Grpc.Core.Utils;
using Grpc.Reflection;
using Grpc.Reflection.V1Alpha;
using NUnit.Framework;

Loading…
Cancel
Save