MCPcopy Index your code
hub / github.com/docker/cli / parallelOperation

Function parallelOperation

cli/command/container/utils.go:52–82  ·  view source on GitHub ↗
(ctx context.Context, containers []string, op func(ctx context.Context, containerID string) error)

Source from the content-addressed store, hash-verified

50}
51
52func parallelOperation(ctx context.Context, containers []string, op func(ctx context.Context, containerID string) error) chan error {
53 if len(containers) == 0 {
54 return nil
55 }
56 const defaultParallel int = 50
57 sem := make(chan struct{}, defaultParallel)
58 errChan := make(chan error)
59
60 // make sure result is printed in correct order
61 output := map[string]chan error{}
62 for _, c := range containers {
63 output[c] = make(chan error, 1)
64 }
65 go func() {
66 for _, c := range containers {
67 err := <-output[c]
68 errChan <- err
69 }
70 }()
71
72 go func() {
73 for _, c := range containers {
74 sem <- struct{}{} // Wait for active queue sem to drain.
75 go func(container string) {
76 output[container] <- op(ctx, container)
77 <-sem
78 }(c)
79 }
80 }()
81 return errChan
82}

Callers 5

runStopFunction · 0.85
runKillFunction · 0.85
runUnpauseFunction · 0.85
runRmFunction · 0.85
runPauseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…