(ctx context.Context, next chan Item, observe <-chan Item, operatorFactory func() operator, bypassGather bool, option Option, opts ...Option)
| 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{} |
| 305 | _, pool := option.getPool() |
| 306 | wg.Add(pool) |
| 307 | |
| 308 | var gather chan Item |
| 309 | if bypassGather { |
| 310 | gather = next |
| 311 | } else { |
| 312 | gather = make(chan Item, 1) |
| 313 | |
| 314 | // Gather |
| 315 | go func() { |
| 316 | op := operatorFactory() |
| 317 | stopped := false |
| 318 | operator := operatorOptions{ |
| 319 | stop: func() { |
| 320 | if option.getErrorStrategy() == StopOnError { |
| 321 | stopped = true |
| 322 | } |
| 323 | }, |
| 324 | resetIterable: func(newIterable Iterable) { |
| 325 | observe = newIterable.Observe(opts...) |
| 326 | }, |
| 327 | } |
| 328 | for item := range gather { |
| 329 | if stopped { |
| 330 | break |
| 331 | } |
| 332 | if item.Error() { |
| 333 | op.err(ctx, item, next, operator) |
| 334 | } else { |
| 335 | op.gatherNext(ctx, item, next, operator) |
| 336 | } |
| 337 | } |
| 338 | op.end(ctx, next) |
| 339 | close(next) |
| 340 | }() |
| 341 | } |
| 342 | |
| 343 | // Scatter |
| 344 | for i := 0; i < pool; i++ { |
| 345 | go func() { |
| 346 | op := operatorFactory() |
| 347 | stopped := false |
| 348 | operator := operatorOptions{ |
| 349 | stop: func() { |
| 350 | if option.getErrorStrategy() == StopOnError { |
| 351 | stopped = true |
| 352 | } |
| 353 | }, |
| 354 | resetIterable: func(newIterable Iterable) { |
| 355 | observe = newIterable.Observe(opts...) |
| 356 | }, |
| 357 | } |
| 358 | defer wg.Done() |
| 359 | for !stopped { |
| 360 | select { |
no test coverage detected
searching dependent graphs…