Hi, I'm having a problem with `BroadcastChannel`. ...
# coroutines
g
Hi, I'm having a problem with
BroadcastChannel
.
Copy code
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 C
m
Can you provide
myApiCall
as well, so we can reproduce it?
g
myApiCall
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.