Is it correct to use `yield()` for interfacing non...
# coroutines
n
Is it correct to use
yield()
for interfacing non-blocking functions from an external library? Like this example code:
Copy code
while (...) {
    val r: Int = nonBlockingFunction() // Returns -1 if no data available
    if (r == -1) {
        yield() // Is this a correct way to "wait" in the coroutine?
    } else {
        ... // Do something with the data
    }
}
e
while (true) yield()
will allow other coroutines to run, but it always returns to the back of the runqueue so you'll spin 100% of CPU doing it. in general, I would not call that "correct"
n
I see... what do you recommend? Calling
delay(x)
instead does not seem "reactive" enough.
e
a non-blocking API must have some way to notify you when it's actually ready