Norbi
02/13/2023, 6:12 PMyield()
for interfacing non-blocking functions from an external library? Like this example 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
}
}
ephemient
02/13/2023, 6:20 PMwhile (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"Norbi
02/13/2023, 7:07 PMdelay(x)
instead does not seem "reactive" enough.ephemient
02/13/2023, 7:10 PM