Skip to content

Commit

Permalink
Handle termination signals
Browse files Browse the repository at this point in the history
  • Loading branch information
yankeexe committed Sep 5, 2021
1 parent d4e4f83 commit 2791943
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package cmd
import (
"fmt"
"os"
"os/signal"
"syscall"

"github.com/gookit/color"
fuzzyfinder "github.com/ktr0731/go-fuzzyfinder"
Expand Down Expand Up @@ -48,6 +50,15 @@ var searchCmd = &cobra.Command{
os.Exit(1)
}

killSignal := make(chan os.Signal, 1)
signal.Notify(killSignal, os.Interrupt, syscall.SIGTERM)

go func() {
<-killSignal
fmt.Println("Search stopped")
os.Exit(130)
}()

searchQuery := args[0]
res, err := aqi.HTTPClient.Fetch(searchQuery)
if err != nil {
Expand Down

0 comments on commit 2791943

Please sign in to comment.