Skip to content

Commit a567fee

Browse files
BrennanConroyBrennan
authored and
Brennan
committed
add bcl.asyncinterfaces
1 parent 88aa6ff commit a567fee

File tree

8 files changed

+12
-20
lines changed

8 files changed

+12
-20
lines changed

eng/Dependencies.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ and are generated based on the last package release.
4242
<LatestPackageReference Include="Microsoft.AspNetCore.Testing" Version="$(MicrosoftAspNetCoreTestingPackageVersion)" />
4343
<LatestPackageReference Include="Microsoft.Azure.KeyVault" Version="$(MicrosoftAzureKeyVaultPackageVersion)" />
4444
<LatestPackageReference Include="Microsoft.Azure.Storage.Blob" Version="$(MicrosoftAzureStorageBlobPackageVersion)" />
45+
<LatestPackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="$(MicrosoftBclAsyncInterfaces)" />
4546
<LatestPackageReference Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildFrameworkPackageVersion)" />
4647
<LatestPackageReference Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildUtilitiesCorePackageVersion)" />
4748
<LatestPackageReference Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisCommonPackageVersion)" />

eng/Version.Details.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@
293293
<Uri>https://github.com/aspnet/Extensions</Uri>
294294
<Sha>2d3e9b5b4c0cf8cc76c0861980ad82e5ea23429e</Sha>
295295
</Dependency>
296+
<Dependency Name="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0-preview7.19309.4" CoherentParentDependency="Microsoft.NETCore.App">
297+
<Uri>https://github.com/dotnet/corefx</Uri>
298+
<Sha>46d9f33d96a1db41a9634b84dd68256db2eeed4f</Sha>
299+
</Dependency>
296300
<Dependency Name="Microsoft.CSharp" Version="4.6.0-preview7.19309.4" CoherentParentDependency="Microsoft.NETCore.App">
297301
<Uri>https://github.com/dotnet/corefx</Uri>
298302
<Sha>46d9f33d96a1db41a9634b84dd68256db2eeed4f</Sha>

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<MicrosoftNETCoreAppPackageVersion>3.0.0-preview7-27809-08</MicrosoftNETCoreAppPackageVersion>
6565
<NETStandardLibraryRefPackageVersion>2.1.0-preview7-27809-08</NETStandardLibraryRefPackageVersion>
6666
<!-- Packages from dotnet/corefx -->
67+
<MicrosoftBclAsyncInterfaces>1.0.0-preview7.19309.4</MicrosoftBclAsyncInterfaces>
6768
<MicrosoftCSharpPackageVersion>4.6.0-preview7.19309.4</MicrosoftCSharpPackageVersion>
6869
<MicrosoftWin32RegistryPackageVersion>4.6.0-preview7.19309.4</MicrosoftWin32RegistryPackageVersion>
6970
<SystemComponentModelAnnotationsPackageVersion>4.6.0-preview7.19309.4</SystemComponentModelAnnotationsPackageVersion>

src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ public partial class HubConnection
4949
};
5050

5151
private static readonly MethodInfo _sendStreamItemsMethod = typeof(HubConnection).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Single(m => m.Name.Equals(nameof(SendStreamItems)));
52-
#if NETSTANDARD2_1 || NETCOREAPP3_0
5352
private static readonly MethodInfo _sendIAsyncStreamItemsMethod = typeof(HubConnection).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Single(m => m.Name.Equals(nameof(SendIAsyncEnumerableStreamItems)));
54-
#endif
53+
5554
// Persistent across all connections
5655
private readonly ILoggerFactory _loggerFactory;
5756
private readonly ILogger _logger;
@@ -522,7 +521,6 @@ private async Task StopAsyncCore(bool disposing)
522521
}
523522
}
524523

525-
#if NETSTANDARD2_1 || NETCOREAPP3_0
526524
/// <summary>
527525
/// Invokes a streaming hub method on the server using the specified method name, return type and arguments.
528526
/// </summary>
@@ -559,7 +557,6 @@ private async IAsyncEnumerable<T> CastIAsyncEnumerable<T>(string methodName, obj
559557
cts.Dispose();
560558
}
561559
}
562-
#endif
563560

564561
private async Task<ChannelReader<object>> StreamAsChannelCoreAsyncCore(string methodName, Type returnType, object[] args, CancellationToken cancellationToken)
565562
{
@@ -674,15 +671,13 @@ private void LaunchStreams(ConnectionState connectionState, Dictionary<string, o
674671
// For each stream that needs to be sent, run a "send items" task in the background.
675672
// This reads from the channel, attaches streamId, and sends to server.
676673
// A single background thread here quickly gets messy.
677-
#if NETSTANDARD2_1 || NETCOREAPP3_0
678674
if (ReflectionHelper.IsIAsyncEnumerable(reader.GetType()))
679675
{
680676
_ = _sendIAsyncStreamItemsMethod
681677
.MakeGenericMethod(reader.GetType().GetInterface("IAsyncEnumerable`1").GetGenericArguments())
682678
.Invoke(this, new object[] { connectionState, kvp.Key.ToString(), reader, cancellationToken });
683679
continue;
684680
}
685-
#endif
686681
_ = _sendStreamItemsMethod
687682
.MakeGenericMethod(reader.GetType().GetGenericArguments())
688683
.Invoke(this, new object[] { connectionState, kvp.Key.ToString(), reader, cancellationToken });
@@ -707,7 +702,6 @@ async Task ReadChannelStream(CancellationTokenSource tokenSource)
707702
return CommonStreaming(connectionState, streamId, token, ReadChannelStream);
708703
}
709704

710-
#if NETSTANDARD2_1 || NETCOREAPP3_0
711705
// this is called via reflection using the `_sendIAsyncStreamItemsMethod` field
712706
private Task SendIAsyncEnumerableStreamItems<T>(ConnectionState connectionState, string streamId, IAsyncEnumerable<T> stream, CancellationToken token)
713707
{
@@ -724,7 +718,6 @@ async Task ReadAsyncEnumerableStream(CancellationTokenSource tokenSource)
724718

725719
return CommonStreaming(connectionState, streamId, token, ReadAsyncEnumerableStream);
726720
}
727-
#endif
728721

729722
private async Task CommonStreaming(ConnectionState connectionState, string streamId, CancellationToken token, Func<CancellationTokenSource, Task> createAndConsumeStream)
730723
{

src/SignalR/clients/csharp/Client.Core/src/HubConnectionExtensions.StreamAsync.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ namespace Microsoft.AspNetCore.SignalR.Client
1414
/// </summary>
1515
public static partial class HubConnectionExtensions
1616
{
17-
18-
#if NETSTANDARD2_1 || NETCOREAPP3_0
19-
2017
/// <summary>
2118
/// Invokes a streaming hub method on the server using the specified method name and return type.
2219
/// </summary>
@@ -236,7 +233,5 @@ public static IAsyncEnumerable<TResult> StreamAsync<TResult>(this HubConnection
236233
{
237234
return hubConnection.StreamAsyncCore<TResult>(methodName, new[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 }, cancellationToken);
238235
}
239-
#endif
240-
241236
}
242237
}

src/SignalR/clients/csharp/Client.Core/src/Microsoft.AspNetCore.SignalR.Client.Core.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>Client for ASP.NET Core SignalR</Description>
@@ -28,6 +28,10 @@
2828
<Reference Include="System.Threading.Channels" />
2929
</ItemGroup>
3030

31+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
32+
<Reference Include="Microsoft.Bcl.AsyncInterfaces" />
33+
</ItemGroup>
34+
3135
<ItemGroup Condition="'$(AspNetCoreMajorMinorVersion)' == '3.0'">
3236
<!-- This dependency was replaced by Protocols.NewtonsoftJson between 3.0 and 2.2. This suppression can be removed after 3.0 is complete. -->
3337
<SuppressBaselineReference Include="Microsoft.AspNetCore.SignalR.Protocols.Json" />

src/SignalR/common/Shared/AsyncEnumerableAdapters.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace Microsoft.AspNetCore.SignalR.Internal
1313
// True-internal because this is a weird and tricky class to use :)
1414
internal static class AsyncEnumerableAdapters
1515
{
16-
#if NETSTANDARD2_1 || NETCOREAPP3_0
1716
public static IAsyncEnumerable<object> MakeCancelableAsyncEnumerable<T>(IAsyncEnumerable<T> asyncEnumerable, CancellationToken cancellationToken = default)
1817
{
1918
return new CancelableAsyncEnumerable<T>(asyncEnumerable, cancellationToken);
@@ -142,6 +141,5 @@ public ValueTask DisposeAsync()
142141
}
143142
}
144143
}
145-
#endif
146144
}
147145
}

src/SignalR/common/Shared/ReflectionHelper.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ public static bool IsStreamingType(Type type, bool mustBeDirectType = false)
1616
{
1717
// TODO #2594 - add Streams here, to make sending files easy
1818

19-
#if NETSTANDARD2_1 || NETCOREAPP3_0
2019
if (IsIAsyncEnumerable(type))
2120
{
2221
return true;
2322
}
24-
#endif
2523
do
2624
{
2725
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ChannelReader<>))
@@ -35,7 +33,6 @@ public static bool IsStreamingType(Type type, bool mustBeDirectType = false)
3533
return false;
3634
}
3735

38-
#if NETSTANDARD2_1 || NETCOREAPP3_0
3936
public static bool IsIAsyncEnumerable(Type type)
4037
{
4138
if (type.IsGenericType)
@@ -55,6 +52,5 @@ public static bool IsIAsyncEnumerable(Type type)
5552
}
5653
});
5754
}
58-
#endif
5955
}
6056
}

0 commit comments

Comments
 (0)