If you want to avoid @MainActor annotation you could use @unchecked Sendable annotation at class level to tell compiler you will be managing. Usually Net handlers are only one per app process so it will be safe.
In the line:
try await self.onNetworkStateChanged(networkConnectionState: state)
Try using an eternal reference for your net manager and avoid weak self
private func setupNetworkMonitoring() async {
let netManager = self
await networkMonitor.startMonitoring { state in
guard let self = self else { return }
Task {
// ⬇ ⬇ ⬇ Capture of 'self' with non-sendable type 'NetworkService' in a `@Sendable` closure
try await netManager.onNetworkStateChanged(networkConnectionState: state)
}
}
}