diesieben07
01/09/2020, 9:36 AMflow
solution (it doesn't work for bidirectional streaming), so I am back to fighting with channels.
I need to explicitly request more elements from upstream when the channel runs empty (i.e. receive
needs to suspend because the buffer is empty).
I thought I could "just implement ReceiveChannel", but this proved difficult, because it's not just a simple interface with suspend fun receive
...
override suspend fun receive(): E {
val element = delegate.poll()
if (element != null) return element
api.request(bufferSize)
return delegate.receive()
}
This is not correct, because other ways to receive (such as onReceive
) would have to all be implemented from scratch... This doesn't sound right...
Is there really no simple way to do this?Zach Klippenstein (he/him) [MOD]
01/09/2020, 10:32 PMreceive needs to suspend because the buffer is emptyThis is already how channels work, why do you want a custom implementation?
diesieben07
01/09/2020, 10:34 PMrequest
.diesieben07
01/09/2020, 10:34 PMZach Klippenstein (he/him) [MOD]
01/09/2020, 10:35 PMlaunchReceive
function doing this already? It loops and sends things into the channel. It will keep doing that as long as the channel isn’t full, and then suspend until it has capacity again.diesieben07
01/09/2020, 10:36 PMdiesieben07
01/09/2020, 10:37 PMZach Klippenstein (he/him) [MOD]
01/09/2020, 10:37 PMdiesieben07
01/09/2020, 10:39 PMZach Klippenstein (he/him) [MOD]
01/09/2020, 10:41 PMdiesieben07
01/09/2020, 10:42 PM