I would like to have the result of multiple observables combined into a parent observable. I don't have access to all the observables at once, they will be subscribed throughout the execution of the program.
So far this was my approach:
...
compoundObservable = compoundObservable.mergeWith(firstObservable);
...
compoundObservable = compoundObservable.mergeWith(secondObservable);
...
The approach hasn't worked, as the events sent by the otherObservable aren't registered by the subscribers of the compoundObservable.
How can I combine these observables?
Subjectbe an option in your case? - LamorakfirstObservableandsecondObservablewill be created only after someone has subscribed to (what was then)compoundOversable? - david.miholafirstObservableandsecondObservablehave already been created. I'm looking to accumulate the result of each observable in thecompoundObservable. As for aSubjectI'm open to it - post an answer! - bkachcompoundObservable? The crucial point is that all Observables are immutable:mergeWithreturns a new instance that's different from the previous value ofcompoundObservable, even though you're using the same variable name to keep it. The main point is: You'd have tomerge(With)before subscribing - if you merge afterwards you'll just never use the merged Observable. - david.mihola