StartWith emits a specified Iterable before beginning to emit the items from the source Observable.
(iterable Iterable, opts ...Option)
| 2239 | |
| 2240 | // StartWith emits a specified Iterable before beginning to emit the items from the source Observable. |
| 2241 | func (o *ObservableImpl) StartWith(iterable Iterable, opts ...Option) Observable { |
| 2242 | option := parseOptions(opts...) |
| 2243 | next := option.buildChannel() |
| 2244 | ctx := option.buildContext(o.parent) |
| 2245 | |
| 2246 | go func() { |
| 2247 | defer close(next) |
| 2248 | observe := iterable.Observe(opts...) |
| 2249 | loop1: |
| 2250 | for { |
| 2251 | select { |
| 2252 | case <-ctx.Done(): |
| 2253 | break loop1 |
| 2254 | case i, ok := <-observe: |
| 2255 | if !ok { |
| 2256 | break loop1 |
| 2257 | } |
| 2258 | if i.Error() { |
| 2259 | next <- i |
| 2260 | return |
| 2261 | } |
| 2262 | i.SendContext(ctx, next) |
| 2263 | } |
| 2264 | } |
| 2265 | observe = o.Observe(opts...) |
| 2266 | loop2: |
| 2267 | for { |
| 2268 | select { |
| 2269 | case <-ctx.Done(): |
| 2270 | break loop2 |
| 2271 | case i, ok := <-observe: |
| 2272 | if !ok { |
| 2273 | break loop2 |
| 2274 | } |
| 2275 | if i.Error() { |
| 2276 | i.SendContext(ctx, next) |
| 2277 | return |
| 2278 | } |
| 2279 | i.SendContext(ctx, next) |
| 2280 | } |
| 2281 | } |
| 2282 | }() |
| 2283 | |
| 2284 | return &ObservableImpl{ |
| 2285 | iterable: newChannelIterable(next), |
| 2286 | } |
| 2287 | } |
| 2288 | |
| 2289 | // SumFloat32 calculates the average of float32 emitted by an Observable and emits a float32. |
| 2290 | func (o *ObservableImpl) SumFloat32(opts ...Option) OptionalSingle { |
nothing calls this directly
no test coverage detected