-
-
Notifications
You must be signed in to change notification settings - Fork 362
refactor(INetworkMonitorService): add reuse state function #6409
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
Conversation
# Conflicts: # src/BootstrapBlazor.Server/Components/Samples/NetworkMonitors.razor.cs # src/BootstrapBlazor/Services/DefaultNetworkMonitorService.cs
Reviewer's GuideThis refactor adds a reuse mechanism for the last known network state in DefaultNetworkMonitorService—caching incoming states, immediately invoking newly registered callbacks with the cached state, and introducing a semaphore timeout—while also updating the sample component for nullable logging. Sequence diagram for RegisterStateChangedCallback with state reusesequenceDiagram
participant Component
participant DefaultNetowrkMonitorService
participant Callback
Component->>DefaultNetowrkMonitorService: RegisterStateChangedCallback(callback)
DefaultNetowrkMonitorService->>DefaultNetowrkMonitorService: Add or update callback in _callbacks
alt _state is not null
DefaultNetowrkMonitorService->>Callback: Invoke callback(_state)
end
alt !_init
DefaultNetowrkMonitorService->>DefaultNetowrkMonitorService: Wait on _semaphoreSlim (timeout 3000ms)
DefaultNetowrkMonitorService->>DefaultNetowrkMonitorService: Set _init = true (if not already)
end
Class diagram for DefaultNetowrkMonitorService state reuse refactorclassDiagram
class DefaultNetowrkMonitorService {
- ConcurrentDictionary<IComponent, Func<NetworkMonitorState, Task>> _callbacks
- bool _init
- SemaphoreSlim _semaphoreSlim
- NetworkMonitorState? _state
+ DefaultNetowrkMonitorService(IJSRuntime jsRuntime)
+ Task<NetworkMonitorState> GetNetworkMonitorState(CancellationToken token)
+ Task RegisterStateChangedCallback(IComponent component, Func<NetworkMonitorState, Task> callback)
+ void UnregisterStateChangedCallback(IComponent component)
+ Task TriggerNetworkStateChanged(NetworkMonitorState state)
}
DefaultNetowrkMonitorService --> IJSRuntime
DefaultNetowrkMonitorService --> IComponent
DefaultNetowrkMonitorService --> NetworkMonitorState
DefaultNetowrkMonitorService --> SemaphoreSlim
Class diagram for NetworkMonitors sample component logger updateclassDiagram
class NetworkMonitors {
- ConsoleLogger? _logger
+ Task OnNetworkStateChanged(NetworkMonitorState state)
}
NetworkMonitors --> ConsoleLogger
NetworkMonitors --> NetworkMonitorState
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ArgoZhang - I've reviewed your changes and they look great!
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Link issues
fixes #6408
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Refactor DefaultNetworkMonitorService to persist and reuse the latest network state for late-registered callbacks, introduce a timeout for semaphore acquisition, and update the sample component to safely handle a nullable logger
New Features:
Bug Fixes:
Enhancements: