code: func (s *State) Wait(ctx context.Context, condition WaitCondition) <-chan StateStatus {
  	s.Lock()
  	defer s.Unlock()
  
  	if condition == WaitConditionNotRunning && !s.Running {
  		// Buffer so we can put it in the channel now.
  		resultC := make(chan StateStatus, 1)
  
  		// Send the current status.
  		resultC <- StateStatus{
  			exitCode: s.ExitCode(),
  			err:      s.Err(),
  		}
  
  		return resultC
  	}
  
  	// If we are waiting only for removal, the waitStop channel should
  	// remain nil and block forever.
  	var waitStop chan struct{}
  	if condition < WaitConditionRemoved {
  		waitStop = s.waitStop
  	}
  
  	// Always wait for removal, just in case the container gets removed
  	// while it is still in a "created" state, in which case it is never
  	// actually stopped.
  	waitRemove := s.waitRemove
  
  	resultC := make(chan StateStatus)
  
  	go func() {
  		select {
  		case <-ctx.Done():
  			// Context timeout or cancellation.
  			resultC <- StateStatus{
  				exitCode: -1,
  				err:      ctx.Err(),
  			}
  			return
  		case <-waitStop:
  		case <-waitRemove:
  		}
  
  		s.Lock()
  		result := StateStatus{
  			exitCode: s.ExitCode(),
  			err:      s.Err(),
  		}
  		s.Unlock()
  
  		resultC <- result
  	}()
  
  	return resultC
  }
docs: // Wait waits until the container is in a certain state indicated by the given
  // condition. A context must be used for cancelling the request, controlling
  // timeouts, and avoiding goroutine leaks. Wait must be called without holding
  // the state lock. Returns a channel from which the caller will receive the
  // result. If the container exited on its own, the result's Err() method will
  // be nil and its ExitCode() method will return the container's exit code,
  // otherwise, the results Err() method will return an error indicating why the
  // wait operation failed.