Hi there :) we‘re currently developing a Kotlin na...
# kotlin-native
d
Hi there :) we‘re currently developing a Kotlin native app for Windows and want to use Coroutines. As it seems we need to add some kind of Runloop with yield in order to keep them running, does someone know a better idea? Thanks a lot!
g
what do you exactly is doing?
d
Copy code
fun main() = runBlocking<Unit> {
   // UI Work

   while(true) {
      yield() // make Coroutines work
   }
}
This leads to the problem that Coroutines only work when UI is non-blocking
g
make Coroutines work
I’m not sure what you mean
this code above just blocks
main
yield allows to run other dispatched coroutines, but i’m not sure that it way to go
if you have other coroutines in this block, just use .await() or .join() to wait when they finished
d
Okay, how would you allow Coroutines to run? Do we need to build a bridge somehow to the main dispatcher of Windows?
t
ideally that’s what you would do (if you want to dispatch to main). I’d look at the Darwin dispatcher in the native-mt branches for inspiration.
as far as I know these don’t exist for windows yet in the official repo (but maybe double check to make sure), not sure if anyone else made them
g
But runBlocking also works as bridge between coroutines and standard function, but it blocks thread