defhlt
03/11/2017, 1:25 PMproduce
for bridging my callback api I always get ClosedSendChannelException
error.
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:
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:
launch(CommonPool) {
for (v in chan) {
//...
}
}