Osmium
06/15/2021, 6:55 PMlaunch
methods so coroutine hierarchy will be structured.
But. How to deal with callbacks?
fun main() {
GlobalScope.launch {
launch {
root("main") { div("Hello KVision!") }
}
launch {
root("extras") {
button {...}.onClick {
this@launch.launch {
ktorClient.get("/api/users/current") {...} // will not be called
}
}
}
}
}
}
Should I use GlobalScope in case of event listeners like onClick and so on?louiscad
06/15/2021, 7:37 PMsuspendCancellableCoroutine
. Name example: awaitOneClick()
Osmium
06/15/2021, 8:35 PMfun setup(parentScope: CoroutineScope) {
val job = Job()
val scope = CoroutineScope(job)
button {}.onClick {
scope.launch { job.complete() }
}
scope.launch { job.join() }
}
Osmium
06/15/2021, 8:35 PMlouiscad
06/15/2021, 8:49 PMRobert Jaros
06/16/2021, 7:16 AMonClickLaunch()
extension function from kvision-event-flow
module which is suspending and using internal KVision coroutine scope.