kingsley
03/04/2017, 7:35 AM// File A: Some repository
fun fetchFooAsync = async(CommonPool) { ... }
// File B: Android activity
private val job = Job()
fun loadFooIntoUI() {
launch(Android + job) {
fetchFooAsync().await()
...
}
}
When the activity in B is getting destroyed, I can easily call job.cancel()
, and the coroutine in loadFooIntoUI
is canceled correctly. However, the fetchFooAsync
call still continues indefinitely.
Is there a way to neatly cancel everything altogether without having to explicitly pass job
to fechFooAsync
?deviant
03/04/2017, 9:31 PMfun async(block: suspend CoroutineScope.() -> Unit) {
launch(Android + job, block = block)
}
inside Base Activity (or other lifecycle element like fragment)
and use my version of async instead of launchkingsley
03/04/2017, 11:50 PM