MCPcopy
hub / github.com/docker/compose / Wait

Method Wait

pkg/compose/wait.go:29–66  ·  pkg/compose/wait.go::composeService.Wait
(ctx context.Context, projectName string, options api.WaitOptions)

Source from the content-addressed store, hash-verified

27)
28
29func (s *composeService) Wait(ctx context.Context, projectName string, options api.WaitOptions) (int64, error) {
30 containers, err := s.getContainers(ctx, projectName, oneOffInclude, false, options.Services...)
31 if err != nil {
32 return 0, err
33 }
34 if len(containers) == 0 {
35 return 0, fmt.Errorf("no containers for project %q", projectName)
36 }
37
38 eg, waitCtx := errgroup.WithContext(ctx)
39 var statusCode int64
40 for _, ctr := range containers {
41 eg.Go(func() error {
42 var err error
43 res := s.apiClient().ContainerWait(waitCtx, ctr.ID, client.ContainerWaitOptions{})
44 select {
45 case result := <-res.Result:
46 _, _ = fmt.Fprintf(s.stdout(), "container %q exited with status code %d\n", ctr.ID, result.StatusCode)
47 statusCode = result.StatusCode
48 case err = <-res.Error:
49 }
50 return err
51 })
52 }
53
54 err = eg.Wait()
55 if err != nil {
56 return 42, err // Ignore abort flag in case of error in wait
57 }
58
59 if options.DownProjectOnContainerExit {
60 return statusCode, s.Down(ctx, projectName, api.DownOptions{
61 RemoveOrphans: true,
62 })
63 }
64
65 return statusCode, err
66}

Callers

nothing calls this directly

Calls 6

getContainersMethod · 0.95
apiClientMethod · 0.95
stdoutMethod · 0.95
DownMethod · 0.95
WaitMethod · 0.65
ContainerWaitMethod · 0.45

Tested by

no test coverage detected