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

@@ -42,7 +42,8 @@ class TetheringService : IpNeighbourMonitoringService(), CoroutineScope {
/**
* Writes and critical reads to downstreams should be protected with this context.
*/
override val coroutineContext = newSingleThreadContext("TetheringService") + Job()
private val dispatcher = newSingleThreadContext("TetheringService")
override val coroutineContext = dispatcher + Job()
private val binder = Binder()
private val downstreams = ConcurrentHashMap<String, Downstream>()
private var receiverRegistered = false
@@ -109,6 +110,7 @@ class TetheringService : IpNeighbourMonitoringService(), CoroutineScope {
downstreams.values.forEach { it.destroy() } // force clean to prevent leakage
unregisterReceiver()
cancel()
dispatcher.close()
}
super.onDestroy()
}