Address more coroutine scope leaks

This commit is contained in:
arkon
2021-01-07 18:15:57 -05:00
parent 36f81b4a62
commit 6fb7a85e8a
23 changed files with 85 additions and 83 deletions
@@ -1,21 +1,32 @@
package eu.kanade.tachiyomi.ui.base.presenter
import android.os.Bundle
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel
import nucleus.presenter.RxPresenter
import nucleus.presenter.delivery.Delivery
import rx.Observable
open class BasePresenter<V> : RxPresenter<V>() {
lateinit var presenterScope: CoroutineScope
override fun onCreate(savedState: Bundle?) {
try {
super.onCreate(savedState)
presenterScope = MainScope()
} catch (e: NullPointerException) {
// Swallow this error. This should be fixed in the library but since it's not critical
// (only used by restartables) it should be enough. It saves me a fork.
}
}
override fun onDestroy() {
super.onDestroy()
presenterScope.cancel()
}
/**
* Subscribes an observable with [deliverFirst] and adds it to the presenter's lifecycle
* subscription list.