-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexampleAccessingTaskNames_test.go
48 lines (41 loc) · 1.1 KB
/
exampleAccessingTaskNames_test.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
package sup_test
import (
"context"
"fmt"
"github.com/warpfork/go-sup"
)
// myTask is a very primitive example task.
type myTask struct {
name string
}
// This is the method running in the task.
// (Pretend it doesn't have access to t.name, if you like.)
func (t myTask) Run(ctx context.Context) error {
fmt.Printf("hi from task %v -- my supervision path is %v :)\n",
sup.CtxTaskName(ctx),
sup.CtxTaskPath(ctx),
)
return nil
}
// This method is how the task declares its name in the first place.
func (t myTask) Name() string {
return t.name
}
// This example shows some user-defined Task implementation with custom names,
// and how to access the name of your task from Context objects.
func ExampleSuperviseForkJoin_accessingTaskNames() {
sup.SuperviseRoot(context.Background(),
sup.SuperviseForkJoin("main",
[]sup.Task{
myTask{"one"},
myTask{"two"},
myTask{"three"},
},
),
)
// Unordered Output:
//
// hi from task one -- my supervision path is main/one :)
// hi from task two -- my supervision path is main/two :)
// hi from task three -- my supervision path is main/three :)
}