@Composable
fun Testing() {
val myValue by asdf.collectAsState(initial = "nunya")
LaunchedEffect(token) { Log.e("ABC", "LE with $myValue") }
...
}
val asdf = flow { repeat(10){
emit("a")
delay(2000)
}
}
Why does the above output
Copy code
13:53:45.647 E LE with a
13:53:45.756 E LE with a
I was expecting
LE with nunya
and then
LE with a
, but why is it LE with a, twice?
Colton Idle
03/10/2024, 6:09 PM
Maybe there's a way to actually print out what the value was of the LE's key at the time the LE was launched
s
Stylianos Gakis
03/10/2024, 6:20 PM
Since LaunchedEffect also launches a coroutine I suppose the order in which these things happen result in this.
If you had a log inside a DisposableEffect instead I would expect to see "nunya" instead.
👍 1
m
MR3Y
03/10/2024, 6:42 PM
LaunchedEffect block is scheduled to run on the next frame. this is one of the main differences between LaunchedEffect and DisposableEffect. so, the log statement will never get a chance to be executed before