Skip to content

Commit d63d96c

Browse files
Copilotjfversluis
andcommitted
Address code review: Use property assignment for SnapshotHandler and add path initialization comment
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
1 parent d191b18 commit d63d96c

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.reachability.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,18 @@ static NWPathMonitor SharedMonitor
4040

4141
static NWPath GetCurrentPath()
4242
{
43-
return SharedMonitor?.CurrentPath;
43+
var monitor = SharedMonitor;
44+
var path = monitor?.CurrentPath;
45+
46+
// If path is null, the monitor might not have received its first update yet
47+
// Force initialization by accessing the monitor
48+
if (path == null && monitor != null)
49+
{
50+
// Monitor is started but path not yet available - this is expected on first call
51+
// The monitor will update CurrentPath asynchronously
52+
}
53+
54+
return path;
4455
}
4556

4657
internal static NetworkStatus RemoteHostStatus()
@@ -120,7 +131,7 @@ internal ReachabilityListener()
120131
ReachabilityChanged?.Invoke();
121132
};
122133

123-
pathMonitor.SnapshotHandler += pathUpdateHandler;
134+
pathMonitor.SnapshotHandler = pathUpdateHandler;
124135
pathMonitor.SetQueue(DispatchQueue.DefaultGlobalQueue);
125136
pathMonitor.Start();
126137

@@ -139,11 +150,8 @@ internal void Dispose()
139150
{
140151
if (pathMonitor != null)
141152
{
142-
if (pathUpdateHandler != null)
143-
{
144-
pathMonitor.SnapshotHandler -= pathUpdateHandler;
145-
pathUpdateHandler = null;
146-
}
153+
pathMonitor.SnapshotHandler = null;
154+
pathUpdateHandler = null;
147155
pathMonitor.Cancel();
148156
pathMonitor.Dispose();
149157
pathMonitor = null;

0 commit comments

Comments
 (0)