1

I have a Flowable<String> that returns the LATEST set of String. This is part of a library class. Is there a way for me to return the last 2 strings when a new observer subscribes to this Flowable.

I can make changes to the Flowable to be setup with a BUFFER strategy as well but that would send a whole bunch of elements back to the Observer. What would be a good way to send back 2 previous elements here?

private fun observeFlowable() : Flowable<String> {
  observer().toFlowable(BackpressureStrategy.LATEST)
}


// The listener

private fun observeFlowable() {
    observeFlowable().buffer(2).doSomething()
}

When the observer starts listening, the buffer(2) never gets called as observeFlowable() if it comes in late will never fire.

0 Answers0