I have some code that looks roughly like this:
Completable handle(Observable<Object> inbound) {
return inbound.buffer(1, TimeUnit.Second, 250)
.filter(l -> !l.isEmpty())
.flatMapToCompletable(this::sendToClient);
}
Completable sendToClient(List<Object> list) {
// call IO asynchronously
}
inbound
is a cold observable that is producing in a standard while loop (but on another Thread!). While not disposed, fetch some data and call onNext()
.
The issue I face is that sendToClient
is too "slow", it can't keep up with the speed at which inbound
is producing data. It's an async operation that is essentially queuing the calls to the client in memory somewhere (don't have access to this code) and eventually filling the heap.
I need a way to figure out a way to get inbound
to stop producing when these calls start to stack up. Is there a way to achieve this using inbuild operators?