| 264 | } |
| 265 | |
| 266 | func runSequential(ctx context.Context, next chan Item, iterable Iterable, operatorFactory func() operator, option Option, opts ...Option) { |
| 267 | observe := iterable.Observe(opts...) |
| 268 | go func() { |
| 269 | op := operatorFactory() |
| 270 | stopped := false |
| 271 | operator := operatorOptions{ |
| 272 | stop: func() { |
| 273 | if option.getErrorStrategy() == StopOnError { |
| 274 | stopped = true |
| 275 | } |
| 276 | }, |
| 277 | resetIterable: func(newIterable Iterable) { |
| 278 | observe = newIterable.Observe(opts...) |
| 279 | }, |
| 280 | } |
| 281 | |
| 282 | loop: |
| 283 | for !stopped { |
| 284 | select { |
| 285 | case <-ctx.Done(): |
| 286 | break loop |
| 287 | case i, ok := <-observe: |
| 288 | if !ok { |
| 289 | break loop |
| 290 | } |
| 291 | if i.Error() { |
| 292 | op.err(ctx, i, next, operator) |
| 293 | } else { |
| 294 | op.next(ctx, i, next, operator) |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | op.end(ctx, next) |
| 299 | close(next) |
| 300 | }() |
| 301 | } |
| 302 | |
| 303 | func runParallel(ctx context.Context, next chan Item, observe <-chan Item, operatorFactory func() operator, bypassGather bool, option Option, opts ...Option) { |
| 304 | wg := sync.WaitGroup{} |