Amb¶
See also
- Official ReactiveX documentation: Amb
-
classmethod
Observable.
amb
(*args)¶ Propagates the observable sequence that reacts first.
Example:
winner = rx.Observable.amb(xs, ys, zs)
Returns: an observable sequence that surfaces any of the given sequences, whichever reacted first. Return type: Observable >>> import rx >>> source = rx.Observable.amb( ... rx.Observable.timer(500).select(lambda x: 'foo'), ... rx.Observable.timer(200).select(lambda x: 'bar')) >>> subscription = source.subscribe( ... lambda value: print("Next:", value), ... lambda error: print("Error:", error), ... lambda: print("Complete!") Next: bar Complete!
With marbles:
>>> import rx >>> from rx.testing import marbles >>> source = rx.Observable.amb( ... rx.Observable.from_marbles('a-b-c-|'), ... rx.Observable.from_marbles('-s-t-u-|')) >>> subscription = source.subscribe( ... lambda value: print("Next:", value), ... lambda error: print("Error:", error), ... lambda: print("Complete!") Next: a Next: b Next: c Complete!