Added overloads from 0-n arguments (#949)
- Added 0 arg overload for InvokeAsync
This commit is contained in:
parent
9df8d2f795
commit
e17cdae046
|
|
@ -131,32 +131,32 @@ namespace Microsoft.AspNetCore.SignalR.Client
|
|||
_handlers.AddOrUpdate(methodName, invocationHandler, (_, __) => invocationHandler);
|
||||
}
|
||||
|
||||
public async Task<ReadableChannel<object>> StreamAsync(string methodName, Type returnType, CancellationToken cancellationToken, params object[] args)
|
||||
public async Task<ReadableChannel<object>> StreamAsync(string methodName, Type returnType, object[] args, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return await StreamAsyncCore(methodName, returnType, cancellationToken).ForceAsync();
|
||||
return await StreamAsyncCore(methodName, returnType, args, cancellationToken).ForceAsync();
|
||||
}
|
||||
|
||||
private async Task<ReadableChannel<object>> StreamAsyncCore(string methodName, Type returnType, CancellationToken cancellationToken, params object[] args)
|
||||
private async Task<ReadableChannel<object>> StreamAsyncCore(string methodName, Type returnType, object[] args, CancellationToken cancellationToken)
|
||||
{
|
||||
var irq = InvocationRequest.Stream(cancellationToken, returnType, GetNextId(), _loggerFactory, out var channel);
|
||||
await InvokeCore(methodName, irq, args, nonBlocking: false);
|
||||
return channel;
|
||||
}
|
||||
|
||||
public async Task<object> InvokeAsync(string methodName, Type returnType, CancellationToken cancellationToken, params object[] args) =>
|
||||
await InvokeAsyncCore(methodName, returnType, cancellationToken, args).ForceAsync();
|
||||
public async Task<object> InvokeAsync(string methodName, Type returnType, object[] args, CancellationToken cancellationToken = default(CancellationToken)) =>
|
||||
await InvokeAsyncCore(methodName, returnType, args, cancellationToken).ForceAsync();
|
||||
|
||||
private async Task<object> InvokeAsyncCore(string methodName, Type returnType, CancellationToken cancellationToken, params object[] args)
|
||||
private async Task<object> InvokeAsyncCore(string methodName, Type returnType, object[] args, CancellationToken cancellationToken)
|
||||
{
|
||||
var irq = InvocationRequest.Invoke(cancellationToken, returnType, GetNextId(), _loggerFactory, out var task);
|
||||
await InvokeCore(methodName, irq, args, nonBlocking: false);
|
||||
return await task;
|
||||
}
|
||||
|
||||
public async Task SendAsync(string methodName, CancellationToken cancellationToken, params object[] args) =>
|
||||
await SendAsyncCore(methodName, cancellationToken, args).ForceAsync();
|
||||
public async Task SendAsync(string methodName, object[] args, CancellationToken cancellationToken = default(CancellationToken)) =>
|
||||
await SendAsyncCore(methodName, args, cancellationToken).ForceAsync();
|
||||
|
||||
private Task SendAsyncCore(string methodName, CancellationToken cancellationToken, params object[] args)
|
||||
private Task SendAsyncCore(string methodName, object[] args, CancellationToken cancellationToken)
|
||||
{
|
||||
var irq = InvocationRequest.Invoke(cancellationToken, typeof(void), GetNextId(), _loggerFactory, out _);
|
||||
return InvokeCore(methodName, irq, args, nonBlocking: true);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Client
|
||||
{
|
||||
public partial class HubConnectionExtensions
|
||||
{
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, Array.Empty<object>(), cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3, arg4 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, object[] args, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (hubConnection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hubConnection));
|
||||
}
|
||||
|
||||
return hubConnection.InvokeAsync(methodName, typeof(object), args, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Client
|
||||
{
|
||||
public static partial class HubConnectionExtensions
|
||||
{
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, Array.Empty<object>(), cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.InvokeAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static async Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, object[] args, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (hubConnection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hubConnection));
|
||||
}
|
||||
|
||||
return (TResult)await hubConnection.InvokeAsync(methodName, typeof(TResult), args, cancellationToken);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Client
|
||||
{
|
||||
public static partial class HubConnectionExtensions
|
||||
{
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, Array.Empty<object>(), cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3, arg4 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 }, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks.Channels;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Client
|
||||
{
|
||||
public static partial class HubConnectionExtensions
|
||||
{
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, Array.Empty<object>(), cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return hubConnection.StreamAsync<TResult>(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 }, cancellationToken);
|
||||
}
|
||||
|
||||
public static async Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, object[] args, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (hubConnection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hubConnection));
|
||||
}
|
||||
|
||||
var inputChannel = await hubConnection.StreamAsync(methodName, typeof(TResult), args, cancellationToken);
|
||||
var outputChannel = Channel.CreateUnbounded<TResult>();
|
||||
|
||||
// Local function to provide a way to run async code as fire-and-forget
|
||||
// The output channel is how we signal completion to the caller.
|
||||
async Task RunChannel()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (await inputChannel.WaitToReadAsync())
|
||||
{
|
||||
while (inputChannel.TryRead(out var item))
|
||||
{
|
||||
while (!outputChannel.Out.TryWrite((TResult)item))
|
||||
{
|
||||
if (!await outputChannel.Out.WaitToWriteAsync())
|
||||
{
|
||||
// Failed to write to the output channel because it was closed. Nothing really we can do but abort here.
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Manifest any errors in the completion task
|
||||
await inputChannel.Completion;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
outputChannel.Out.TryComplete(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// This will safely no-op if the catch block above ran.
|
||||
outputChannel.Out.TryComplete();
|
||||
}
|
||||
}
|
||||
|
||||
_ = RunChannel();
|
||||
|
||||
return outputChannel.In;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -8,95 +8,11 @@ using System.Threading.Tasks.Channels;
|
|||
|
||||
namespace Microsoft.AspNetCore.SignalR.Client
|
||||
{
|
||||
public static class HubConnectionExtensions
|
||||
public static partial class HubConnectionExtensions
|
||||
{
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, params object[] args) =>
|
||||
InvokeAsync(hubConnection, methodName, CancellationToken.None, args);
|
||||
|
||||
public static Task InvokeAsync(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken, params object[] args)
|
||||
{
|
||||
if (hubConnection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hubConnection));
|
||||
}
|
||||
|
||||
return hubConnection.InvokeAsync(methodName, typeof(object), cancellationToken, args);
|
||||
}
|
||||
|
||||
public static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, params object[] args) =>
|
||||
InvokeAsync<TResult>(hubConnection, methodName, CancellationToken.None, args);
|
||||
|
||||
public async static Task<TResult> InvokeAsync<TResult>(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken, params object[] args)
|
||||
{
|
||||
if (hubConnection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hubConnection));
|
||||
}
|
||||
|
||||
return (TResult)await hubConnection.InvokeAsync(methodName, typeof(TResult), cancellationToken, args);
|
||||
}
|
||||
|
||||
public static Task SendAsync(this HubConnection hubConnection, string methodName, params object[] args)
|
||||
{
|
||||
return hubConnection.SendAsync(methodName, CancellationToken.None, args);
|
||||
}
|
||||
|
||||
public static Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, params object[] args) =>
|
||||
StreamAsync<TResult>(hubConnection, methodName, CancellationToken.None, args);
|
||||
|
||||
public static async Task<ReadableChannel<TResult>> StreamAsync<TResult>(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken, params object[] args)
|
||||
{
|
||||
if (hubConnection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(hubConnection));
|
||||
}
|
||||
|
||||
var inputChannel = await hubConnection.StreamAsync(methodName, typeof(TResult), cancellationToken, args);
|
||||
var outputChannel = Channel.CreateUnbounded<TResult>();
|
||||
|
||||
// Local function to provide a way to run async code as fire-and-forget
|
||||
// The output channel is how we signal completion to the caller.
|
||||
async Task RunChannel()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (await inputChannel.WaitToReadAsync())
|
||||
{
|
||||
while (inputChannel.TryRead(out var item))
|
||||
{
|
||||
while (!outputChannel.Out.TryWrite((TResult)item))
|
||||
{
|
||||
if (!await outputChannel.Out.WaitToWriteAsync())
|
||||
{
|
||||
// Failed to write to the output channel because it was closed. Nothing really we can do but abort here.
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Manifest any errors in the completion task
|
||||
await inputChannel.Completion;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
outputChannel.Out.TryComplete(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// This will safely no-op if the catch block above ran.
|
||||
outputChannel.Out.TryComplete();
|
||||
}
|
||||
}
|
||||
|
||||
_ = RunChannel();
|
||||
|
||||
return outputChannel.In;
|
||||
}
|
||||
|
||||
private static void On(this HubConnection hubConnetion, string methodName, Type[] parameterTypes, Action<object[]> handler)
|
||||
{
|
||||
hubConnetion.On(methodName, parameterTypes, (parameters) =>
|
||||
hubConnetion.On(methodName, parameterTypes, (parameters) =>
|
||||
{
|
||||
handler(parameters);
|
||||
return Task.CompletedTask;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,17 @@ namespace Microsoft.AspNetCore.SignalR
|
|||
{
|
||||
public static class IClientProxyExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="clientProxy">The <see cref="IClientProxy"/></param>
|
||||
/// <param name="method">name of the method to invoke</param>
|
||||
/// <returns>A task that represents when the data has been sent to the client.</returns>
|
||||
public static Task InvokeAsync(this IClientProxy clientProxy, string method)
|
||||
{
|
||||
return clientProxy.InvokeAsync(method, Array.Empty<object>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Reference in New Issue