nil2l
12/11/2017, 10:53 AMgildor
12/11/2017, 10:55 AMNetworkCallStateProducer
and can just create channel and cache it to propertynil2l
12/11/2017, 10:56 AMnil2l
12/11/2017, 11:00 AMprivate val channel = Channel< NetworkCallState<T> >()
fun getChannel(): ReceiveChannel< NetworkCallState<T> > = channel
suspend fun produce() {
do {
val state: NetworkCallState<T> = suspendCoroutine { cont = it }
channel.send(state)
} while (!state.status.isCompleted())
channel.close()
}
gildor
12/11/2017, 11:20 AMnil2l
12/11/2017, 11:23 AMChannel<State>
for a call.
I know sync calls should be used here. But currently I can use only async calls.gildor
12/11/2017, 11:27 AMwhile
there, you just return channel. Also, you probably want something like BroadcastChannel to support multiple consumers, now you should create a channel for each consumergildor
12/11/2017, 11:28 AMnil2l
12/11/2017, 11:31 AM(state) -> Unit
gildor
12/11/2017, 11:41 AMoffer
instead of send
nil2l
12/11/2017, 11:42 AMnil2l
12/11/2017, 11:44 AMgetChannel().find { it.status.isCompleted() }
.uli
12/11/2017, 8:32 PMoffer
.it might loose your `state`object if the consume is to slowuli
12/11/2017, 8:34 PMuli
12/11/2017, 8:35 PMuli
12/11/2017, 8:35 PMuli
12/11/2017, 8:39 PMuli
12/11/2017, 8:42 PMchannel.send()
inside run.blocking {}
inside your callback? There you have your coroutine context and depending on the network stack, you might even get back pressure, if the consumer is too slow.