diff --git a/Makefile b/Makefile index 85be503..d33184d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ .PHONY: test test: - go test ./... + go test -race -cpu 5 ./... diff --git a/stream/iterator.go b/stream/iterator.go index b9e1d4c..2ca7fbd 100644 --- a/stream/iterator.go +++ b/stream/iterator.go @@ -5,15 +5,6 @@ import ( "math/big" ) -type NodeIterator struct { - *ReadItem - LastError error - needFeedback bool - items chan *ReadItem - feedback chan error - feedbackClosed bool -} - type ReadItem struct { Path []interface{} TokenType ReaderToken @@ -152,6 +143,15 @@ func (s *ReadItem) ToFloat() (res float64, ok bool) { return res, ok } +type NodeIterator struct { + *ReadItem + LastError error + needFeedback bool + items chan *ReadItem + feedback chan error + feedbackClosed bool +} + // Read from a NodeReader using a channel of ReadItem. func Iterate(r NodeReader, res_error *error) *NodeIterator { it := make(chan *ReadItem) @@ -160,12 +160,10 @@ func Iterate(r NodeReader, res_error *error) *NodeIterator { go func() { err := r.Read(func(path []interface{}, tokenType ReaderToken, value interface{}) error { - res.needFeedback = true item := &ReadItem{path, tokenType, value} it <- item return <-feedback }) - res.needFeedback = false close(it) if err != nil && res_error != nil { res.LastError = err @@ -182,6 +180,7 @@ func (s *NodeIterator) Iter() bool { item := <-s.items if item == nil { + s.needFeedback = false if !s.feedbackClosed { close(s.feedback) s.feedbackClosed = true @@ -189,6 +188,7 @@ func (s *NodeIterator) Iter() bool { return false } + s.needFeedback = true s.ReadItem = item return true }