https://kotlinlang.org logo
Title
g

Gabriel Feo

02/08/2020, 8:08 PM
Exposing a
suspend fun
from a nested Fragment to be called by the parent Fragment. What’d happen if the nested Fragment gets killed before the suspension point returns?
o

octylFractal

02/08/2020, 8:28 PM
depends on who's calling the suspend fun, if it runs in the nested Frag context then it will be canceled, if it runs in the parent Frag context then it won't
g

Gabriel Feo

02/08/2020, 8:40 PM
It’d be called from the parent fragment. Do you know a way to simulate a Fragment being killed, without the Activity being killed?
This library is an example, it attaches a child fragment to a parent fragment and suspends for the permission results: https://github.com/sagar-viradiya/eazypermissions/blob/master/coroutinespermission/src/main/java/com/eazypermissions/coroutinespermission/PermissionManager.kt
o

octylFractal

02/08/2020, 9:00 PM
the deferred is a different case
if the fragment is removed from memory, it's likely that the deferred's continuation would be removed too
thus the coroutine would never resume
s

shaktiman_droid

02/08/2020, 9:52 PM
@sagar-viradiya Q on your library above ^^