I have two streams signaling when some conditions change. I need an Observable which will fire true
when all the conditions turn true
. false
when any of them turns false
. If some of the conditions is false
and another changes to false
I don't need to raise events.
Here is how I'm doing it:
// Introducing current states
private bool cond1 = false;
private bool cond2 = false;
void MyHandlingMethod(IObservable<bool> c1, IObservable<bool> c2)
{
c1.Subscribe(b => _state1 = b);
c2.Subscribe(b => _state2 = b);
var c3 = c1.Merge(c2).Select(_ => _cond1 && _cond2);
c3.Subscribe(b => /* some action goes here /*);
// ...
}
I want to know if it's the right way solve my problem and if there are any pitfals. Eg c3 subscription fires before c1 and c2 due to asynchronous nature of rx.