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

@@ -149,7 +149,8 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
/**
* Writes and critical reads to routingManager should be protected with this context.
*/
override val coroutineContext = newSingleThreadContext("RepeaterService") + Job()
private val dispatcher = newSingleThreadContext("RepeaterService")
override val coroutineContext = dispatcher + Job()
private var routingManager: RoutingManager? = null
private var persistNextGroup = false
@@ -419,6 +420,7 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
launch { // force clean to prevent leakage
cleanLocked()
cancel()
dispatcher.close()
}
if (Build.VERSION.SDK_INT < 29) @Suppress("DEPRECATION") {
app.pref.unregisterOnSharedPreferenceChangeListener(this)