We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cc7d73b commit fabecd1Copy full SHA for fabecd1
cliutil/worker.go
@@ -0,0 +1,30 @@
1
+package cliutil
2
+
3
+import (
4
+ "log"
5
+ "os"
6
+ "os/signal"
7
+ "syscall"
8
+)
9
10
+// EventListener listens for SIGINT and SIGTERM signals and notifies the
11
+// shutdown channel if it detects that either one was sent.
12
+func EventListener() <-chan bool {
13
+ shutdown := make(chan bool)
14
15
+ go func() {
16
+ ch := make(chan os.Signal)
17
+ signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
18
19
+ for {
20
+ select {
21
+ case <-ch:
22
+ log.Println("[NOTICE] shutdown signal received")
23
+ shutdown <- true
24
+ break
25
+ }
26
27
+ }()
28
29
+ return shutdown
30
+}
0 commit comments