Anyone else find the naming of
lifecycleScope.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.