3

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.

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
vach
  • 10,571
  • 12
  • 68
  • 106

2 Answers2

3

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

Gluck
  • 2,933
  • 16
  • 28
0

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?

Germann Arlington
  • 3,315
  • 2
  • 17
  • 19
  • Well the thing is that i cannot (and its not really seem a good idea) to change those apis providing A and B, both do make perfect sense, and i sure can do what i want with some crap code using PublishSubject, however i wondered if there is something like .onErrorContinue() but for completion like .onCompletionContinue(Observable nextStream)... – vach Dec 24 '15 at 11:45
  • Its not that i cannot implement this, its just matter of doing that the proper way :) – vach Dec 24 '15 at 11:45