spand
09/30/2020, 9:28 AMby lazy
variable with coroutines. I can call async(start = Lazy){ expensiveCalculation }
but afaik it does not make the computation optional, only delayed. What am I missing?renatomrcosta
09/30/2020, 9:31 AMval myFlow = flow {
emit(WHATEVER)
}
...
val getMyStuffLazily = myflow.collect()
At first glance, it wouldn’t solve the issue for multiple access to the variable, but it may be at least an interesting way to start thinking about modeling the issuelouiscad
09/30/2020, 9:31 AMspand
09/30/2020, 9:42 AMgildor
09/30/2020, 9:49 AMbut afaik it does not make the computation optional, only delayedWhat do you mean? computation is optional, until someone call .await() on it
gildor
09/30/2020, 9:50 AMlouiscad
09/30/2020, 9:52 AMlazy
. Otherwise, it can keep a CoroutineScope
alive (which doesn't matter in most cases though).gildor
09/30/2020, 9:53 AMrenatomrcosta
09/30/2020, 9:53 AMgildor
09/30/2020, 9:53 AMgildor
09/30/2020, 9:53 AMgildor
09/30/2020, 9:53 AMrenatomrcosta
09/30/2020, 9:53 AMlouiscad
09/30/2020, 9:54 AMlouiscad
09/30/2020, 9:54 AMbut why it should be wrapped to lazy?To not put a (lazy) child coroutine in the host
CoroutineScope
that could keep it alive if await()
is never called and the scope never cancelled.gildor
09/30/2020, 9:55 AMgildor
09/30/2020, 9:56 AMspand
09/30/2020, 9:56 AMgildor
09/30/2020, 9:56 AMlouiscad
09/30/2020, 9:56 AMgildor
09/30/2020, 9:56 AMgildor
09/30/2020, 9:56 AMgildor
09/30/2020, 9:57 AMlouiscad
09/30/2020, 9:57 AMlouiscad
09/30/2020, 9:57 AMrenatomrcosta
09/30/2020, 9:58 AMgildor
09/30/2020, 9:58 AMlouiscad
09/30/2020, 9:59 AMlouiscad
09/30/2020, 10:00 AMcoroutineScope
"was tired waiting", that'd be another bad gotcha