mosaic
mosaic copied to clipboard
Use effects to denote scope of work
Currently we build our own coroutine scope to encapsulate all of the work required to render. When this scope ends, rendering ends and the program exits cleanly (modulo internal nonsense to make this work).
Ideally effects inside the composition are used to scope the composition instead. Compose internals currently prevent this, which is tracked as https://issuetracker.google.com/issues/169425431.
Today:
fun main() = runMosaic {
val countValue = mutableStateOf(0)
setContent {
val count by remember { countValue }
Text("The count is: $count")
}
for (i in 1..20) {
delay(250)
countValue.value = i
}
}
Tomorrow:
fun main() = runMosaic {
val count by remember { mutableStateOf(0) }
Text("The count is: $count")
LaunchedEffect(null) {
for (i in 1..20) {
delay(250)
count++
}
}
}
I was doing some Compose UI for Desktop recently, and it seems like they support this internally. Need to investigate.
I think what you need is something like FlushCoroutineDispatcher
from Compose Multiplatform.
Done in #284