forked from adamlaska/containerd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.go
More file actions
50 lines (42 loc) · 957 Bytes
/
task.go
File metadata and controls
50 lines (42 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package supervisor
import (
"context"
"sync"
"github.com/containerd/containerd/runtime"
)
// StartResponse is the response containing a started container
type StartResponse struct {
ExecPid int
Container runtime.Container
}
// Task executes an action returning an error chan with either nil or
// the error from executing the task
type Task interface {
// ErrorCh returns a channel used to report and error from an async task
ErrorCh() chan error
// Ctx carries the context of a task
Ctx() context.Context
}
type baseTask struct {
errCh chan error
ctx context.Context
mu sync.Mutex
}
func (t *baseTask) WithContext(ctx context.Context) {
t.mu.Lock()
defer t.mu.Unlock()
t.ctx = ctx
}
func (t *baseTask) Ctx() context.Context {
t.mu.Lock()
defer t.mu.Unlock()
return t.ctx
}
func (t *baseTask) ErrorCh() chan error {
t.mu.Lock()
defer t.mu.Unlock()
if t.errCh == nil {
t.errCh = make(chan error, 1)
}
return t.errCh
}