WaitOnService waits for the service to converge. It outputs a progress bar, if appropriate based on the CLI flags.
(ctx context.Context, dockerCli command.Cli, serviceID string, quiet bool)
| 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 := jsonstream.Display(ctx, pipeReader, dockerCli.Out()) |
| 28 | if err == nil { |
| 29 | err = <-errChan |
| 30 | } |
| 31 | return err |
| 32 | } |