Skip to content

Commit

Permalink
support ReadAllAsync for netstandard2.0 (#2411)
Browse files Browse the repository at this point in the history
Co-authored-by: James Newton-King <james@newtonking.com>
  • Loading branch information
WeihanLi and JamesNK committed Apr 17, 2024
1 parent c04d01a commit 9cd97ce
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<PackageVersion Include="Google.Api.CommonProtos" Version="2.13.0" />
<PackageVersion Include="Google.Apis.Auth" Version="1.46.0" />
<PackageVersion Include="Google.Protobuf" Version="3.24.0" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.5.5" />
<PackageVersion Include="Microsoft.Build" Version="16.9.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0-preview.23472.1" />
Expand Down
4 changes: 0 additions & 4 deletions src/Grpc.Net.Common/AsyncStreamReaderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#endregion

#if !NETSTANDARD2_0 && !NET462

using System.Runtime.CompilerServices;
using Grpc.Shared;

Expand Down Expand Up @@ -50,5 +48,3 @@ private static async IAsyncEnumerable<T> ReadAllAsyncCore<T>(IAsyncStreamReader<
}
}
}

#endif
4 changes: 4 additions & 0 deletions src/Grpc.Net.Common/Grpc.Net.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
<ProjectReference Include="..\Grpc.Core.Api\Grpc.Core.Api.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions test/Grpc.Net.Client.Tests/Grpc.Net.Client.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

<ItemGroup Condition="'$(TargetFramework)'=='net462'">
<Reference Include="System.Net.Http" />

<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions test/Grpc.Net.Client.Tests/ReadAllAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
using Grpc.Tests.Shared;
using NUnit.Framework;

#if !NET462

namespace Grpc.Net.Client.Tests;

[TestFixture]
Expand Down Expand Up @@ -275,5 +273,3 @@ public async Task MoveNextAsync_CancelCall_ThrowOperationCanceledOnCancellation_
Assert.AreEqual(StatusCode.Cancelled, call.GetStatus().StatusCode);
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

<ItemGroup Condition="'$(TargetFramework)'=='net462'">
<Reference Include="System.Net.Http" />

<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
</ItemGroup>

</Project>
4 changes: 1 addition & 3 deletions test/Shared/TaskExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand Down Expand Up @@ -102,7 +102,6 @@ private static string CreateMessage(TimeSpan timeout, string? filePath, int line
? $"The operation timed out after reaching the limit of {timeout.TotalMilliseconds}ms."
: $"The operation at {filePath}:{lineNumber} timed out after reaching the limit of {timeout.TotalMilliseconds}ms.";

#if !NET462
public static IAsyncEnumerable<T> DefaultTimeout<T>(this IAsyncEnumerable<T> enumerable,
[CallerFilePath] string? filePath = null,
[CallerLineNumber] int lineNumber = default)
Expand Down Expand Up @@ -169,5 +168,4 @@ public ValueTask<bool> MoveNextAsync()
return new ValueTask<bool>(_enumerator.MoveNextAsync().AsTask().TimeoutAfter(_timeout, _filePath, _lineNumber));
}
}
#endif
}

0 comments on commit 9cd97ce

Please sign in to comment.