Reputation: 117
Lets say that I'm reading a file line by line with this mock example
Flowable.fromArray("a","b","c","d")
Now I want to send each of these lines to backend. Lets use this mock observable to simplify:
Single.timer(1, TimeUnit.Seconds).map{true}
This returns true to emulate successful response.
I want to continue sending lines one by one, waiting for a success signal before sending another.
Would this be possible ? What is the cleanest solution ?
Upvotes: 0
Views: 353
Reputation: 94871
It sounds like you want concatMapSingle
:
Maps the upstream items into SingleSources and subscribes to them one after the other succeeds, emits their success values or terminates immediately if either this Flowable or the current inner SingleSource fail.
Flowable.fromArray("a","b","c","d")
.concatMapSingle(item -> /* Send item to backend */)
Upvotes: 3