MCPcopy Create free account
hub / github.com/ReactiveX/RxGo / runParallel

Function runParallel

observable.go:303–384  ·  view source on GitHub ↗
(ctx context.Context, next chan Item, observe <-chan Item, operatorFactory func() operator, bypassGather bool, option Option, opts ...Option)

Source from the content-addressed store, hash-verified

301}
302
303func 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 {

Callers 3

observableFunction · 0.85
singleFunction · 0.85
optionalSingleFunction · 0.85

Calls 10

OfFunction · 0.85
SendContextMethod · 0.80
getPoolMethod · 0.65
getErrorStrategyMethod · 0.65
ObserveMethod · 0.65
ErrorMethod · 0.65
errMethod · 0.65
gatherNextMethod · 0.65
endMethod · 0.65
nextMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…