-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_basic_test.go
More file actions
52 lines (42 loc) · 982 Bytes
/
example_basic_test.go
File metadata and controls
52 lines (42 loc) · 982 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
51
52
package bootseq_test
import (
"context"
"fmt"
"github.com/mkock/bootseq"
"strings"
)
func Example_basic() {
// Let's use a boot sequence to construct a sentence!
// For the shutdown sequence, we'll "deconstruct" it by removing each word.
var words []string
add := func(word string) func() error {
return func() error {
words = append(words, word)
return nil
}
}
rm := func() error {
words = words[:len(words)-1]
return nil
}
seq := bootseq.New("Basic Example")
seq.Add("welcome", add("Welcome"), rm)
seq.Add("to", add("to"), rm)
seq.Add("my", add("my"), rm)
seq.Add("world", add("world!"), rm)
i, err := seq.Sequence("welcome > to > my > world")
if err != nil {
panic(err)
}
// Bootup sequence.
up := i.Up(context.Background())
up.Wait()
fmt.Println(strings.Join(words, " "))
// Shutdown sequence.
down := up.Down(context.Background())
down.Wait()
fmt.Println(strings.Join(words, " "))
// Output:
// Welcome to my world!
//
}