MCPcopy Create free account
hub / github.com/ReactiveX/RxGo / Amb

Function Amb

factory.go:13–62  ·  view source on GitHub ↗

Amb takes several Observables, emit all of the items from only the first of these Observables to emit an item or notification.

(observables []Observable, opts ...Option)

Source from the content-addressed store, hash-verified

11// Amb takes several Observables, emit all of the items from only the first of these Observables
12// to emit an item or notification.
13func Amb(observables []Observable, opts ...Option) Observable {
14 option := parseOptions(opts...)
15 ctx := option.buildContext(emptyContext)
16 next := option.buildChannel()
17 once := sync.Once{}
18
19 f := func(o Observable) {
20 it := o.Observe(opts...)
21
22 select {
23 case <-ctx.Done():
24 return
25 case item, ok := <-it:
26 if !ok {
27 return
28 }
29 once.Do(func() {
30 defer close(next)
31 if item.Error() {
32 next <- item
33 return
34 }
35 next <- item
36 for {
37 select {
38 case <-ctx.Done():
39 return
40 case item, ok := <-it:
41 if !ok {
42 return
43 }
44 if item.Error() {
45 next <- item
46 return
47 }
48 next <- item
49 }
50 }
51 })
52 }
53 }
54
55 for _, o := range observables {
56 go f(o)
57 }
58
59 return &ObservableImpl{
60 iterable: newChannelIterable(next),
61 }
62}
63
64// CombineLatest combines the latest item emitted by each Observable via a specified function
65// and emit items based on the results of this function.

Callers 3

TestLeakFunction · 0.85
Test_Amb1Function · 0.85
Test_Amb2Function · 0.85

Calls 6

parseOptionsFunction · 0.85
newChannelIterableFunction · 0.85
buildContextMethod · 0.65
buildChannelMethod · 0.65
ObserveMethod · 0.65
ErrorMethod · 0.65

Tested by 3

TestLeakFunction · 0.68
Test_Amb1Function · 0.68
Test_Amb2Function · 0.68