-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterfaces.go
55 lines (48 loc) · 1.74 KB
/
interfaces.go
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
51
52
53
54
55
package edgerunner
import (
"context"
"io"
)
type (
ListenCloser interface {
// Listen starts a long-lived component.
// It is the caller's responsibility to call Listen on the Runner.
// It is the Runner's responsibility to call Listen on Task values
// provided via the TaskFactory.
Listen()
// Closer should cause the Listen method to terminate.
// The Runner waits until Listen has finished.
io.Closer
}
Runner interface {
ListenCloser
// Reload sends a signal to the Runner to invoke the supplied
// TaskFactory to build a new Task instance. If the new Task
// initializes without error and indicates its readiness via
// the supplied `chan<- bool` (see the TaskFactory) the runner
// will call Close on the previously running Task (if any).
// Both the old and new Task values will be running simultaneously
// for a short time (by design).
Reload()
}
)
type (
// Task describes a type supplied by the caller, via the TaskFactory.
// Generally a task is a long-lived component (like an HTTP server).
Task interface {
// Initialize provides an opportunity for the task to load its
// configuration, incorporating the supplied context.Context for
// operations that support it. This step should only prepare to
// perform the work but should not perform any significant work
// which might block termination signals from being handled.
Initialize(ctx context.Context) error
ListenCloser
}
// TaskFactory is a callback for building whatever task will be managed
// by the Runner. The supplied task should call the ready func to indicate
// its readiness to begin working. Only the first call has any effect.
TaskFactory func(id int, ready func(bool)) Task
)
type logger interface {
Printf(string, ...any)
}