refactor(service): initialize PacketHandler lazily (#2833)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich 2025-08-25 11:26:57 -05:00 committed by GitHub
parent 6895af1653
commit 9fd184d3ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -211,8 +211,14 @@ class MeshService :
MeshServiceBroadcasts(this, clientPackages) {
connectionState.also { radioConfigRepository.setConnectionState(it) }
}
private lateinit var packetHandler: PacketHandler
private val packetHandler: PacketHandler by lazy {
PacketHandler(
packetRepository = packetRepository,
serviceBroadcasts = serviceBroadcasts,
radioInterfaceService = radioInterfaceService,
meshLogRepository = meshLogRepository,
)
}
private val serviceJob = Job()
private val serviceScope = CoroutineScope(Dispatchers.IO + serviceJob)
private var connectionState = ConnectionState.DISCONNECTED
@ -330,14 +336,6 @@ class MeshService :
loadSettings() // Load our last known node DB
packetHandler =
PacketHandler(
packetRepository = packetRepository,
serviceBroadcasts = serviceBroadcasts,
radioInterfaceService = radioInterfaceService,
meshLogRepository = meshLogRepository,
)
// the rest of our init will happen once we are in radioConnection.onServiceConnected
}