3
votes

I'm having hard time finding proper way of composing an observable which will emit all items from the given cold observable A and as soon as its completes continue with hot observable B.

This is my specific use case : I have a data collector which in realtime appends data to the append only database (an event stream). And when a request arrives for streaming all the event stream it is expected to start streaming everything from database and as soon as database has no more data it shall start streaming whatever the collector streams... as you see both are available as observables.

I'm new to reactive programming, hence my question may be a bit abstract. Any help appreciated.

Here is a diagram for this behavior :

B ----B---B---B----B--B---B---B---X------>
                   |  |   |   |   |
                   |  |   |   |   |
R --A---A--A----?--B--B---B---B---X------>
    |   |  |    |
    |   |  |    |
A --A---A--A----X------------------------>

Here R is our result observable and A is the cold one, B is the hot one. R is terminating with B.

2

2 Answers

3
votes

If B is hot, then simply A.concat(B) should work, because B will be subscribed to only when A finishes.

0
votes

I suspect that what you need is 2 queues, not observables.

QueueA has a priority and QueueB is only processed once QueueA gets a quit/end of messages signal.

Do you think that this scenario may be suitable?