spierce7
02/15/2019, 2:34 PMprotected open val coroutineExceptionHandler: CoroutineExceptionHandler? = null
private var _mountScope = ComponentCoroutineScope()
private var _viewScope = ComponentCoroutineScope()
protected val mountScope: CoroutineScope
get() = _mountScope
protected val viewScope: CoroutineScope
get() = _viewScope
private inner class ComponentCoroutineScope : CoroutineScope {
private val baseJob = Job()
val isActive: Boolean = baseJob.isActive
override val coroutineContext: CoroutineContext
get() {
val job = Job(parent = baseJob) + Dispatchers.Main
return coroutineExceptionHandler?.let { job + it } ?: job
}
fun cancel() {
baseJob.cancel()
}
}
In a child presenter class:
override val coroutineExceptionHandler: CoroutineExceptionHandler?
get() = ApiCoroutineExceptionHandler(apiExceptionHandler)
gildor
02/15/2019, 2:42 PMspierce7
02/15/2019, 2:43 PMgildor
02/15/2019, 2:43 PMspierce7
02/15/2019, 2:43 PMgildor
02/15/2019, 2:44 PMspierce7
02/15/2019, 2:45 PMgildor
02/15/2019, 2:54 PMspierce7
02/15/2019, 3:01 PMuhe
02/15/2019, 3:08 PMstreetsofboston
02/15/2019, 3:17 PMJob
comes in handy if it is tied to the Coroutine-Scope’s context.
If you don’t want all other siblings to fail, use SupervisorJob
. Not sure if I like the name, though 🙂uhe
02/15/2019, 3:21 PMspierce7
02/15/2019, 3:22 PMgildor
02/15/2019, 3:26 PMspierce7
02/15/2019, 3:26 PMstreetsofboston
02/15/2019, 3:27 PMspierce7
02/15/2019, 3:27 PMgildor
02/15/2019, 3:35 PMspierce7
02/15/2019, 3:37 PMgildor
02/15/2019, 3:47 PMDico
02/16/2019, 3:40 PMspierce7
02/17/2019, 7:36 PMDico
02/17/2019, 8:50 PMNonCancellable