Giorgio Antonioli
03/11/2019, 1:48 PMBroadcastChannel
.
private val getChannel = BroadcastChannel<String>(1)
fun myApiCallbackNotSuspended() {
runBlocking {
println("X")
getChannel.send("result")
println("Y")
}
}
suspend fun get(): String {
val receiveChannel = getChannel.openSubscription()
println("A")
// It will invoke "myApiCallbackNotSuspended()" on the main thread after some time.
myApiCall()
println("B")
val result = receiveChannel.receive()
println("C)
return result
}
The method myApiCallbackNotSuspended()
is invoked and it sends the result to the channel.
The problem is that receiveChannel.receive()
remains stuck.
I get the message in the following order: A B X Y without getting Cmarstran
03/11/2019, 1:53 PMmyApiCall
as well, so we can reproduce it?Giorgio Antonioli
03/11/2019, 2:10 PMmyApiCall
is a method inside a library which is not open-source. I tried to reproduce the same behavior with another library and it works.
It seems something related to "myApiCall" and channels used together. TBH I have no clue on what to check now.