Skip to content

Commit 8e9fb39

Browse files
committed
feat: add ctrl+c handler
1 parent a228487 commit 8e9fb39

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cmd/fast/main.go

+11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package main
33
import (
44
"flag"
55
"log"
6+
"os"
7+
"os/signal"
68
"sync"
9+
"syscall"
710
"time"
811

912
"github.com/adhocore/chin"
@@ -23,9 +26,17 @@ func main() {
2326
s := chin.New().WithWait(&wg)
2427
go s.Start()
2528

29+
var sig = make(chan os.Signal, 1)
30+
signal.Notify(sig, os.Interrupt, syscall.SIGTERM, syscall.SIGABRT)
31+
2632
wg.Add(1)
2733
go doFast(s, &wg, noUp)
2834

35+
go func() {
36+
<-sig
37+
s.Stop()
38+
}()
39+
2940
wg.Wait()
3041
}
3142

0 commit comments

Comments
 (0)