If I have a KN library code that uses coroutines and I want to call that code for example from C, how would I initialize the event loop?
Right now I am getting this error:`kotlin.IllegalStateException: There is no event loop. Use runBlocking { ... } to start one.`
Patrick
01/21/2020, 11:56 AM
If I call that library from Kotlin, I can just use
fun main() = runBlocking {...}
, but how would I call this with C code?
b
basher
01/21/2020, 1:50 PM
You'd need up create a function that calls runBlocking and then calls your coroutines code inside that
p
Patrick
01/21/2020, 2:05 PM
The problem is that this library is full of coroutine code. And I would like to avoid using runBlocking for each and every function. I guess I could just create an alias for runBlocking and then call everything inside that function but that would look pretty confusing to the developer who would have to use the library I think.
b
basher
01/21/2020, 2:19 PM
Generally, C doesn't support suspend, so I'm not sure how you avoid it
p
Patrick
01/21/2020, 2:45 PM
Yeah I was mainly asking if there is a solution for this already, since this may be a use case that could be very popular, because kotlin coroutines are basically supported on every platform now.
b
basher
01/21/2020, 3:14 PM
AFAIK, there isn't 😕
k
Kavan
01/21/2020, 8:00 PM
Workers are only form of coroutines implemented yet for K/N.