summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2016-11-29 20:34:17 +0100
committerSilvan Jegen <s.jegen@gmail.com>2016-11-29 20:34:17 +0100
commit0175c3063667542f25179c050813cf2b391bba54 (patch)
tree9f8d27cbbd5f9daf9a21109df7d0473d3111209b
parentaf40a95e52ba89c0234c370d0aec3578d62ef696 (diff)
Make sure we do not deadlock
-rw-r--r--manager.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/manager.go b/manager.go
index 0c933ec..91933f9 100644
--- a/manager.go
+++ b/manager.go
@@ -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