github.com/portworx/docker@v1.12.1/daemon/wait.go (about) 1 package daemon 2 3 import ( 4 "time" 5 6 "golang.org/x/net/context" 7 ) 8 9 // ContainerWait stops processing until the given container is 10 // stopped. If the container is not found, an error is returned. On a 11 // successful stop, the exit code of the container is returned. On a 12 // timeout, an error is returned. If you want to wait forever, supply 13 // a negative duration for the timeout. 14 func (daemon *Daemon) ContainerWait(name string, timeout time.Duration) (int, error) { 15 container, err := daemon.GetContainer(name) 16 if err != nil { 17 return -1, err 18 } 19 20 return container.WaitStop(timeout) 21 } 22 23 // ContainerWaitWithContext returns a channel where exit code is sent 24 // when container stops. Channel can be cancelled with a context. 25 func (daemon *Daemon) ContainerWaitWithContext(ctx context.Context, name string) error { 26 container, err := daemon.GetContainer(name) 27 if err != nil { 28 return err 29 } 30 31 return container.WaitWithContext(ctx) 32 }