diff options
author | Silvan Jegen <s.jegen@gmail.com> | 2016-11-29 20:34:17 +0100 |
---|---|---|
committer | Silvan Jegen <s.jegen@gmail.com> | 2016-11-29 20:34:17 +0100 |
commit | 0175c3063667542f25179c050813cf2b391bba54 (patch) | |
tree | 9f8d27cbbd5f9daf9a21109df7d0473d3111209b | |
parent | af40a95e52ba89c0234c370d0aec3578d62ef696 (diff) |
Make sure we do not deadlock
-rw-r--r-- | manager.go | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -59,6 +59,7 @@ func (i *StdinInput) Start() chan *Work { } i.retchan <- &Work{data: bs} } + close(i.retchan) }() return i.retchan @@ -70,21 +71,23 @@ func (f *StringFilter) Filter(ic chan *Work) chan *Work { go func() { for w := range ic { dec := json.NewDecoder(bytes.NewReader(w.data)) + jm := make(map[string]string, 10) - for { - tok, err := dec.Token() - if err == io.EOF { - break - } - if err != nil { - fmt.Printf("Error when reading JSON: %q\n", err) - os.Exit(1) - } - fmt.Printf("Token: %T %v\n", tok, tok) + err := dec.Decode(&jm) + if err == io.EOF { + fmt.Printf("EOF jm: %v\n", jm) + f.retchan <- w + continue + } + if err != nil { + fmt.Printf("Error when decoding JSON: %q\n", err) + w.err = err } + fmt.Printf("jm: %v\n", jm) f.retchan <- w } + close(f.retchan) }() return f.retchan |