iamsteveholmes
01/25/2022, 5:54 PMArkadii Ivanov
01/25/2022, 9:36 PMfun LifecycleOwner.coroutineScope(context: CoroutineContext): CoroutineScope {
val scope = CoroutineScope(context)
lifecycle.doOnDestroy(scope::cancel)
return scope
}
And then use it in a component as follows:
class SomeComponent(componentContext: ComponentContext): ComponentContext by componentContext {
private val scope = coroutineScope(Dispatchers.Main)
}
Arkadii Ivanov
01/25/2022, 10:08 PMiamsteveholmes
01/25/2022, 10:56 PMprivate val output: Consumer<Output>
. But of course Consumer
is a reaktive class. Is there a coroutines equivalent?
`Arkadii Ivanov
01/25/2022, 11:24 PMprivate val output: (Output) -> Unit
Please also keep in mind another way. Instead of having sealed interface Output
and a single function/consumer, you define multiple separate functions:
private val onFinished: () -> Unit,
private val onError: () -> Unit,
// ...
The former option may work better with reactive streams (Flow/Observable), and you can map/combine the streams. But the latter option may be less boilerplate sometimes. Just FYI.