wait.go 931 B

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