Orhan Tozan
11/19/2020, 4:08 PMlifecycleScope.launchWhenStarted {}
misleading?
lifecycleScope.launch { ... }
-> launches the coroutine immediatly, gets canceled when lifecycle is destroyed.
Now I would expect lifecycleScope.launchWhenStarted { ... }
to behave the same as the above, except it being different in the timing of the coroutine launching: coroutine gets launched when the lifecycle is started, and gets canceled when lifecycle is destroyed.
But what it actually does, is also suspend the coroutine after it is launched, when the lifecycle is stopped.
Maybe I've misunderstood it, but if not, I think a more fitting name would be something like lifecycleScope.runWhileStarted {...}
? Or maybe perhaps a whole new scope? (lifecycleStartedScope
), It feels like these launchWhen
methods try to emulate sub-coroutinescopes that could be replaced by introducing new lifecyclescopes that are different instances of CoroutineScope, an API that exists for handling the lifecycles of coroutines.
Curious to hear your thoughts about this.ephemient
11/19/2020, 4:13 PMLifecycle.whenStarted(...)
, but I do agree about LifecycleCoroutineScope
method namingAdam Powell
11/19/2020, 4:26 PMAdam Powell
11/19/2020, 4:27 PMAdam Powell
11/19/2020, 4:29 PMdave08
11/19/2020, 6:21 PMflosch
11/19/2020, 6:22 PMJan Skrasek
11/19/2020, 7:56 PMAdam Powell
11/19/2020, 10:41 PMOrhan Tozan
11/20/2020, 10:48 AMlifescopeScope.launchWhenStarted {}
/ .addLiveLauncher
methods in onCreate
or onViewCreated
?