github.1git.de/docker/cli@v26.1.3+incompatible/cli/command/service/helpers.go (about) 1 package service 2 3 import ( 4 "context" 5 "io" 6 7 "github.com/docker/cli/cli/command" 8 "github.com/docker/cli/cli/command/service/progress" 9 "github.com/docker/docker/pkg/jsonmessage" 10 ) 11 12 // WaitOnService waits for the service to converge. It outputs a progress bar, 13 // if appropriate based on the CLI flags. 14 func WaitOnService(ctx context.Context, dockerCli command.Cli, serviceID string, quiet bool) error { 15 errChan := make(chan error, 1) 16 pipeReader, pipeWriter := io.Pipe() 17 18 go func() { 19 errChan <- progress.ServiceProgress(ctx, dockerCli.Client(), serviceID, pipeWriter) 20 }() 21 22 if quiet { 23 go io.Copy(io.Discard, pipeReader) 24 return <-errChan 25 } 26 27 err := jsonmessage.DisplayJSONMessagesToStream(pipeReader, dockerCli.Out(), nil) 28 if err == nil { 29 err = <-errChan 30 } 31 return err 32 }