From d84e731b4d93db31480e597127c1c1d293ffe559 Mon Sep 17 00:00:00 2001 From: catatsuy Date: Mon, 22 Feb 2021 14:11:36 +0900 Subject: [PATCH] use signal.NotifyContext --- .github/workflows/go.yml | 2 +- cli/cli.go | 19 +++---------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ce6e73e..9e8f511 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 diff --git a/cli/cli.go b/cli/cli.go index 4b5417e..e64690d 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -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 == "" { @@ -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