task.go 645 B

12345678910111213141516171819202122232425262728293031323334
  1. package supervisor
  2. import (
  3. "sync"
  4. "github.com/docker/containerd/runtime"
  5. )
  6. // StartResponse is the response containing a started container
  7. type StartResponse struct {
  8. Container runtime.Container
  9. }
  10. // Task executes an action returning an error chan with either nil or
  11. // the error from executing the task
  12. type Task interface {
  13. // ErrorCh returns a channel used to report and error from an async task
  14. ErrorCh() chan error
  15. }
  16. type baseTask struct {
  17. errCh chan error
  18. mu sync.Mutex
  19. }
  20. func (t *baseTask) ErrorCh() chan error {
  21. t.mu.Lock()
  22. defer t.mu.Unlock()
  23. if t.errCh == nil {
  24. t.errCh = make(chan error, 1)
  25. }
  26. return t.errCh
  27. }