Fix dispatcher not closed

This commit is contained in:
Mygod
2019-07-31 08:53:45 +08:00
parent bed11276b9
commit 1f2ccf83b0
3 changed files with 12 additions and 4 deletions

View File

@@ -46,7 +46,8 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService(), CoroutineScope {
/**
* Writes and critical reads to routingManager should be protected with this context.
*/
override val coroutineContext = newSingleThreadContext("LocalOnlyHotspotService") + Job()
private val dispatcher = newSingleThreadContext("LocalOnlyHotspotService")
override val coroutineContext = dispatcher + Job()
private var routingManager: RoutingManager? = null
private val handler = Handler()
@RequiresApi(28)
@@ -158,7 +159,10 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService(), CoroutineScope {
launch {
routingManager?.destroy()
routingManager = null
if (exit) cancel()
if (exit) {
cancel()
dispatcher.close()
}
}
}
}