For this case, the following should work:
var combined = A.TakeUntil(B).Merge(B);
Frage
I have two IObservable
sequences that will return at most one item before completing. I want to merge them, but while the first sequence will usually complete first, in rare cases may complete second. If it completes second, then I want to ignore its output.
Normal case:
A 1
B - 2
Result 1 2
Rare, "slow A" case:
A - 1
B 2
Result 2
Is there a simple way of doing this? I'm not aware of a way to prematurely end a merged sequence based on which IObservable
triggered the last OnNext
. The best solution I have is to Select
and return a Tuple
indicating which sequence the value came from, and simply ignoring everything after a "B" result.
Lösung
For this case, the following should work:
var combined = A.TakeUntil(B).Merge(B);
Andere Tipps
If we have two variables for our streams IObservable<int> a,b;
then:
IObservable<int> result = a.TakeUntil(b).Merge(b);