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

Function newEventSourceIterable

iterable_eventsource.go:15–58  ·  view source on GitHub ↗
(ctx context.Context, next <-chan Item, strategy BackpressureStrategy, opts ...Option)

Source from the content-addressed store, hash-verified

13}
14
15func newEventSourceIterable(ctx context.Context, next <-chan Item, strategy BackpressureStrategy, opts ...Option) Iterable {
16 it := &eventSourceIterable{
17 observers: make([]chan Item, 0),
18 opts: opts,
19 }
20
21 go func() {
22 for {
23 select {
24 case <-ctx.Done():
25 it.closeAllObservers()
26 return
27 case item, ok := <-next:
28 if !ok {
29 it.closeAllObservers()
30 return
31 }
32 it.RLock()
33 switch strategy {
34 default:
35 fallthrough
36 case Block:
37 for _, observer := range it.observers {
38 if !item.SendContext(ctx, observer) {
39 return
40 }
41 }
42 case Drop:
43 for _, observer := range it.observers {
44 select {
45 default:
46 case <-ctx.Done():
47 return
48 case observer <- item:
49 }
50 }
51 }
52 it.RUnlock()
53 }
54 }
55 }()
56
57 return it
58}
59
60func (i *eventSourceIterable) closeAllObservers() {
61 i.Lock()

Callers 2

FromEventSourceFunction · 0.85
IntervalFunction · 0.85

Calls 2

closeAllObserversMethod · 0.95
SendContextMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…