When I’m trying to use `produce` for bridging my c...
# coroutines
d
When I’m trying to use
produce
for bridging my callback api I always get
ClosedSendChannelException
error.
Copy code
fun <T : Any?> stream1() = produce<T>(CommonPool) {
        addCallback(object: Callback<T> {
            override fun onDataChange(value T) {
                offer(value)
            }
        })
    }
Is this expected behaviour? On the other hand creating channel manually works fine:
Copy code
fun <T : Any?> stream2: ReceiveChannel<T> {

        val chan = Channel<T>()

        addCallback(object: Callback<T> {
            override fun onDataChange(value: T) {
                offer(value)
            }
        })

        return chan
    }
Receiving is like this in both cases:
Copy code
launch(CommonPool) {
            for (v in chan) {
                //...
            }
        }