This quesiton is about kotlinx-coroutines-reactive
.
The idea with using suspend functions for backpressure is nice, but the current design has a significant shortcoming: a Kotlin-style publisher must have the next element calculated, and only then can it learn that it’s not needed (via send()
). This is a problem for “expensive” publishers: those for which it’s costly to calculate elements, and you only want to do it if there’s demand from upstream.
Example use case: a Publisher
backed by polling a DB table. In this case, we need to stop polling while there is no demand from upstream. However, the current API doesn’t provide a good way of doing this; the best you can do is to replace DB polling with polling PublisherScope.isFull
.
I’d suggest to add PublisherScope.awaitDemand()
method that would suspend until there’s demand from upstream.