aaverin
08/27/2018, 3:48 PMsend can only be called in coroutine context, that is hidden by the callback functionVsevolod Tolstopyatov [JB]
08/27/2018, 4:11 PMSendChannel<E>.sendBlocking for this purposebj0
08/27/2018, 4:15 PM.offer if you don't mind dropped events, or are using a conflated channelaaverin
08/28/2018, 7:07 PMsendBlocking but get ClosedSendChannelException
code is
produce {
addSnapshotListener { snapshot ->
val list = parseSnapshot(snapshot)
sendBlocking(list)
}
}
Any ideas why is SendChannel already closed?aaverin
08/28/2018, 7:08 PMaaverin
08/28/2018, 7:10 PMVsevolod Tolstopyatov [JB]
08/28/2018, 8:01 PMproduce block ended (e.g. if addSnapshotListener is asynchronous)aaverin
08/28/2018, 8:02 PMaddSnapshotListener is asynchronous, that’s kind of the point of the code I am trying to write
Once in a while I will be getting updates from server socket, and I need to expose them as a channel consumers could subscribe toaaverin
08/28/2018, 8:05 PMsuspendCancelableCoroutine
I am trying to find an equivalent in Channels world so I could keep listening the socket and get all updatesbj0
08/28/2018, 8:47 PMproduce block from suspending, or just use a normal channelaaverin
08/29/2018, 5:29 AMproduce suspending, after all it’s an async operation I am wrapping.
Problem is that send(data) can only be executed within coroutine bodyaaverin
08/29/2018, 5:29 AMbj0
08/29/2018, 5:59 AMproduce block from *ending*", in other words, you need to suspend it somehowbj0
08/29/2018, 5:59 AMproduce ends -> channel closes