Skip to content

Commit

Permalink
use signal.NotifyContext
Browse files Browse the repository at this point in the history
  • Loading branch information
catatsuy committed Feb 28, 2021
1 parent 9864faa commit d84e731
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.15.x', '1.16.x' ]
go: [ '1.16.x' ]
steps:

- name: Set up Go
Expand Down
19 changes: 3 additions & 16 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ func (c *CLI) Run(args []string) int {

ex := throttle.NewExec(copyStdin)

sigC := make(chan os.Signal, 1)
signal.Notify(sigC, syscall.SIGTERM, syscall.SIGINT)
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer stop()

channel := c.conf.PrimaryChannel
if channel == "" {
Expand Down Expand Up @@ -196,20 +196,7 @@ func (c *CLI) Run(args []string) int {
ticker := time.NewTicker(c.conf.Duration)
defer ticker.Stop()

ctx, cancel := context.WithCancel(context.Background())

exitC := make(chan struct{})
go func() {
ex.Start(ctx, ticker.C, flushCallback, doneCallback)
close(exitC)
}()

select {
case <-sigC:
case <-exitC:
}
cancel()

ex.Start(ctx, ticker.C, flushCallback, doneCallback)
<-done

return ExitCodeOK
Expand Down

0 comments on commit d84e731

Please sign in to comment.