(ctx context.Context, next <-chan Item, strategy BackpressureStrategy, opts ...Option)
| 13 | } |
| 14 | |
| 15 | func 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 | |
| 60 | func (i *eventSourceIterable) closeAllObservers() { |
| 61 | i.Lock() |
no test coverage detected
searching dependent graphs…