Hi, I wanted to know some best practices while handling coroutines in Kotlin/Native.
I am dealing with Worker APIs because I have to manually run an event loop for receiving system events, using a coroutine scope and launching through it is waste as the call never will suspend.
Since there is no common pool in the K/N, I am forced to start a new thread (by creating a new CoroutineContext) for emitting value in a SharedFlow. But I think reserving the thread just for emission of the values is still be a waste (Thread is basically just running an event loop and possibly wasting CPU cycles), plus launching may take a little bit of time as well so not so good.
My next guess is to use runBlocking, but I think that'd still be an overkill (if there are alot of events to process, runBlocking might be just wasting time in instantiating a lot of coroutine dependent classes).
What's the correct way of emitting to the flow when not directly under coroutine, specially when emission should be from low level stuffs in K/N?
Slack Conversation