Skip to content

Commit

Permalink
encode: Handle interrupt signal
Browse files Browse the repository at this point in the history
  • Loading branch information
tsenart committed Aug 18, 2018
1 parent d72f3f9 commit f01a574
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions encode.go
Expand Up @@ -5,6 +5,8 @@ import (
"flag"
"fmt"
"io"
"os"
"os/signal"
"strings"

vegeta "github.com/tsenart/vegeta/lib"
Expand Down Expand Up @@ -93,7 +95,16 @@ func encode(files []string, to, output string) error {
return fmt.Errorf("encode: unknown encoding %q", to)
}

sigch := make(chan os.Signal, 1)
signal.Notify(sigch, os.Interrupt)

for {
select {
case <-sigch:
return nil
default:
}

var r vegeta.Result
if err = dec.Decode(&r); err != nil {
if err == io.EOF {
Expand Down

0 comments on commit f01a574

Please sign in to comment.