From 359c996c124b07a3d89b2cc0ff7d7d4eb419b971 Mon Sep 17 00:00:00 2001 From: wadepickett Date: Tue, 16 Jan 2024 20:28:15 -0800 Subject: [PATCH] SignalR Hubs CancelationToken --- aspnetcore/signalr/hubs.md | 36 +++--------------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/aspnetcore/signalr/hubs.md b/aspnetcore/signalr/hubs.md index 690d600391b7..2cbd95889887 100644 --- a/aspnetcore/signalr/hubs.md +++ b/aspnetcore/signalr/hubs.md @@ -123,45 +123,15 @@ In addition to making calls to clients, the server can request a result from a c There are two ways to use the API on the server, the first is to call `Client(...)` or `Caller` on the `Clients` property in a Hub method: -```csharp -public class ChatHub : Hub -{ - public async Task WaitForMessage(string connectionId) - { - var message = await Clients.Client(connectionId).InvokeAsync( - "GetMessage"); - return message; - } -} -``` +:::code language="csharp" source="~/../AspNetCore.Docs.Samples/signalr/hubs/samples/7.x/SignalRHubsSample/Snippets/Hubs/ChatHubClientResults.cs" id="snippet_HubClientReturn" highlight="8-10"::: The second way is to call `Client(...)` on an instance of [`IHubContext`](xref:signalr/hubcontext): -```csharp -async Task SomeMethod(IHubContext context) -{ - string result = await context.Clients.Client(connectionID).InvokeAsync( - "GetMessage"); -} -``` +:::code language="csharp" source="~/../AspNetCore.Docs.Samples/signalr/hubs/samples/7.x/SignalRHubsSample/Snippets/Hubs/ChatHubClientResultsContext.cs" id="snippet_HubClientReturnContext"::: Strongly-typed hubs can also return values from interface methods: -```csharp -public interface IClient -{ - Task GetMessage(); -} - -public class ChatHub : Hub -{ - public async Task WaitForMessage(string connectionId) - { - string message = await Clients.Client(connectionId).GetMessage(); - return message; - } -} -``` +:::code language="csharp" source="~/../AspNetCore.Docs.Samples/signalr/hubs/samples/7.x/SignalRHubsSample/Snippets/Hubs/ChatHubClientResultsStronglyTyped.cs" id="snippet_HubClientResultsStronglyTyped"::: Clients return results in their `.On(...)` handlers, as shown below: