FlatMap transforms the items emitted by an Observable into Observables, then flatten the emissions from those into a single Observable.
(apply ItemToObservable, opts ...Option)
| 1110 | |
| 1111 | // FlatMap transforms the items emitted by an Observable into Observables, then flatten the emissions from those into a single Observable. |
| 1112 | func (o *ObservableImpl) FlatMap(apply ItemToObservable, opts ...Option) Observable { |
| 1113 | f := func(ctx context.Context, next chan Item, option Option, opts ...Option) { |
| 1114 | defer close(next) |
| 1115 | observe := o.Observe(opts...) |
| 1116 | for { |
| 1117 | select { |
| 1118 | case <-ctx.Done(): |
| 1119 | return |
| 1120 | case item, ok := <-observe: |
| 1121 | if !ok { |
| 1122 | return |
| 1123 | } |
| 1124 | observe2 := apply(item).Observe(opts...) |
| 1125 | loop2: |
| 1126 | for { |
| 1127 | select { |
| 1128 | case <-ctx.Done(): |
| 1129 | return |
| 1130 | case item, ok := <-observe2: |
| 1131 | if !ok { |
| 1132 | break loop2 |
| 1133 | } |
| 1134 | if item.Error() { |
| 1135 | item.SendContext(ctx, next) |
| 1136 | if option.getErrorStrategy() == StopOnError { |
| 1137 | return |
| 1138 | } |
| 1139 | } else { |
| 1140 | if !item.SendContext(ctx, next) { |
| 1141 | return |
| 1142 | } |
| 1143 | } |
| 1144 | } |
| 1145 | } |
| 1146 | } |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | return customObservableOperator(o.parent, f, opts...) |
| 1151 | } |
| 1152 | |
| 1153 | // ForEach subscribes to the Observable and receives notifications for each element. |
| 1154 | func (o *ObservableImpl) ForEach(nextFunc NextFunc, errFunc ErrFunc, completedFunc CompletedFunc, opts ...Option) Disposed { |
nothing calls this directly
no test coverage detected