here is my use case:
I have two different Observables:
Observable<MobileAdEvent> adEventStream;
Observable<Color> colorStream;
I need to receive notification when either of those two emits an event. zipWith does not work for me, since it waits until both streams has an event to emit. mergeWith also does not seem to work, since it expects both stream to be from the same type.
Any hints would be greatly appreciated,
Thanks.
What you want is combineLatest operator
Observable<Foo> foo;
Observable<Bar> bar;
final output = Observable.combineLatest2(foo, bar, (Foo foo, Bar bar) {
// TODO: somehow merge them
});
Have you tried Observable.race ? it's perfect for notifications :
Given two or more source streams, emit all of the items from only the first of these streams to emit an item or notification.
new Observable.race([
new Observable.timer(1, new Duration(days: 1)),
new Observable.timer(2, new Duration(days: 2)),
new Observable.timer(3, new Duration(seconds: 1))
]).listen(print); // prints 3
learn more here https://pub.dev/documentation/rxdart/latest/rx/Observable/Observable.race.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With