Untitled.kt
# coroutines
d
Untitled.kt
m
I guess some lock would work but it might be more appropriate for component itself to suspend until ready for more work, at least in given example
d
The other component is a C++ dynamic lib via JNI interface
m
do you get a callback when it's ready for more data or do you have to check a flag?
d
I get a callback
m
You could use a Mutex or Semaphore
d
Thanks! I will look into that
m
Copy code
channel.consumeEach {
        //bit strange but avoids potential deadlock if callback happens on this thread (as Mutex is not reentrant lock)
        mutex.lock()
		mutex.unlock()

        processResults(it)
    }
	
onNotReady() {
	mutex.lock()
}

onReady() {
	mutex.unlock()
}