github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/daemon/wait.go (about)

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