Support parallel rm

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
This commit is contained in:
Zhang Wei
2016-09-21 22:35:08 +08:00
parent f612b93d33
commit 5c1362ce59
2 changed files with 18 additions and 21 deletions

View File

@ -91,8 +91,8 @@ func getExitCode(dockerCli *command.DockerCli, ctx context.Context, containerID
return c.State.Running, c.State.ExitCode, nil
}
func parallelOperation(ctx context.Context, cids []string, op func(ctx context.Context, id string) error) chan error {
if len(cids) == 0 {
func parallelOperation(ctx context.Context, containers []string, op func(ctx context.Context, container string) error) chan error {
if len(containers) == 0 {
return nil
}
const defaultParallel int = 50
@ -101,18 +101,18 @@ func parallelOperation(ctx context.Context, cids []string, op func(ctx context.C
// make sure result is printed in correct order
output := map[string]chan error{}
for _, c := range cids {
for _, c := range containers {
output[c] = make(chan error, 1)
}
go func() {
for _, c := range cids {
for _, c := range containers {
err := <-output[c]
errChan <- err
}
}()
go func() {
for _, c := range cids {
for _, c := range containers {
sem <- struct{}{} // Wait for active queue sem to drain.
go func(container string) {
output[container] <- op(ctx, container)