(ctx context.Context, containers []string, op func(ctx context.Context, containerID string) error)
| 50 | } |
| 51 | |
| 52 | func 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 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…