Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SignalR idle timeout example #32027

Merged
merged 5 commits into from
Mar 11, 2024
Merged

Conversation

guardrex
Copy link
Collaborator

@guardrex guardrex commented Mar 11, 2024

Fixes #32021

Thanks @gerektoolhy! 🚀 ... This will log the ID and fix a few other NITs.

@MackinnonBuck ... The updates seem reasonable 🤔, but I'll wait for you to look because I don't think you saw the original content when it went in. This will give you a chance to look over the entire section in case there are additional remarks to make (e.g., gotchas 😈).


Internal previews

📄 File 🔗 Preview link
aspnetcore/blazor/fundamentals/signalr.md ASP.NET Core Blazor SignalR guidance

@guardrex guardrex self-assigned this Mar 11, 2024
Copy link
Member

@MackinnonBuck MackinnonBuck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just a few questions, feel free to address however you like


```csharp
using Microsoft.AspNetCore.Components.Server.Circuits;
using Microsoft.Extensions.Options;
using Timer = System.Timers.Timer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is using System.Timers; insufficient? Or does that create ambiguity in the code somewhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took that from Dan's code. It looks like going with using System.Timers.Timer; is ambiguous with System.Threading.Timer. I suppose that's why he did it this way.

Here's Dan's code btw ---

https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-dotnet-8-preview-3/#monitor-blazor-server-circuit-activity

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, it's fine how it is!

{
currentCircuit = circuit;

return base.OnCircuitOpenedAsync(circuit, cancellationToken);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary to call the base method here - it doesn't have a meaningful implementation and just returns Task.CompletedTask.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I don't return, I get an error that the OnCircuitOpenedAsync isn't returning a value. How is it set up without returning the base method?

Copy link
Collaborator Author

@guardrex guardrex Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it just return a completed Task? ... rubber 🦆 ... I think I'm answering my own question! 😄

public override Task OnCircuitOpenedAsync(Circuit circuit, 
    CancellationToken cancellationToken)
{
    currentCircuit = circuit;

    return Task.CompletedTask;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, returning Task.CompletedTask is the right move!

@guardrex guardrex merged commit 83204f4 into main Mar 11, 2024
3 checks passed
@guardrex guardrex deleted the guardrex/blazor-signalr-idlehandler branch March 11, 2024 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IdleCircuitHandler should log a meaningful log message
2 participants