Skip to content

Commit fabecd1

Browse files
committed
Added event listener code.
1 parent cc7d73b commit fabecd1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

cliutil/worker.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)