kirillrakhman
03/15/2017, 9:55 AMelizarov
03/15/2017, 10:12 AMkirillrakhman
03/15/2017, 10:27 AMJobHolder
or similar.fun NaviComponent.launch(event: Event<*> = Event.DESTROY, block: suspend CoroutineScope.() -> Unit) {
val job = Job()
addListener(event) { job.cancel() }
launch(job + UI, block = block)
}
fun NaviComponent.launch(event: Event<*> = Event.DESTROY, block: suspend CoroutineScope.() -> Unit) {
val job = launch(UI, block = block)
addListener(event) { job.cancel() }
}
elizarov
03/15/2017, 11:08 AMdeviant
03/15/2017, 11:10 AMjob+UI
is actually pretty cool. you can achieve same behavior with dummy job as with rxlifecycle events Publish object that doing signals on each lifecycle event. so just add
job.cancel()
to your BaseActivity onStop()
i've also done this convenient helper method specifically for activities and fragments:
fun async(block: suspend CoroutineScope.() -> Unit) {
launch(UI + job, block = block)
}
kingsley
03/15/2017, 11:21 AMclass Dispatcher {
fun ui(job: Job) = UI + job
fun io(job: Job) = CommonPool + job
...
}
Perhaps, there's a better way to approach this? 🤔