-
Notifications
You must be signed in to change notification settings - Fork 1
/
debug.go
113 lines (76 loc) · 1.47 KB
/
debug.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/codegangsta/cli"
)
func main() {
app := cli.NewApp()
app.Action = func(c *cli.Context) {
runApp(c)
}
app.Run(os.Args)
}
func runApp(c *cli.Context) {
log.Printf("start waitSmth")
var waitSmth chan int
waitSmth = make(chan int, 1)
go func() {
waitSmth <- 10
//log.Printf("pushed %v", 10)
}()
go func() {
waitSmth <- 20
//log.Printf("pushed %v", 20)
time.Sleep(time.Second * 10)
close(waitSmth)
}()
/*
var r int
for ; r == 0; r = <- waitSmth {
if r > 0 {
log.Printf("waitSmth, %v", r)
}
}
*/
for range waitSmth {
log.Printf("waitSmth")
}
/*
go func() {
log.Printf("start waitSmth1")
var waitSmth <- chan int
waitSmth = make(chan int, 1)
for ; ; <- waitSmth {
log.Printf("waitSmth1")
}
}()
*/
waitShutdown := make(chan error)
sysigs := make(chan os.Signal, 1)
signal.Notify(sysigs, syscall.SIGINT, syscall.SIGTERM)
go func(sigs chan os.Signal, done chan error) {
sig := <-sigs
log.Printf("Got shutdown signal %v", sig)
done <- nil
}(sysigs, waitShutdown)
go func(done chan error) {
lifetimeShutdown(5)
log.Printf("Shutdown on lifetime timeout: %v sec", 5)
done <- nil
}(waitShutdown)
<-waitShutdown
log.Printf("Shutdown finished")
}
func lifetimeShutdown(lifetime int) {
if lifetime > 0 {
time.Sleep(time.Second * time.Duration(lifetime))
} else {
for {
time.Sleep(time.Second)
}
}
}