diff --git a/parser/pbf/process.go b/parser/pbf/process.go index ae36762..eaa4764 100644 --- a/parser/pbf/process.go +++ b/parser/pbf/process.go @@ -49,14 +49,19 @@ func (p *parser) Parse() { }() } p.wg.Wait() -} -func (p *parser) Wait() { - p.wg.Wait() -} - -func (p *parser) Close() { - p.wg.Wait() + if p.nodes != nil { + close(p.nodes) + } + if p.coords != nil { + close(p.coords) + } + if p.ways != nil { + close(p.ways) + } + if p.relations != nil { + close(p.relations) + } } // FinishedCoords registers a single function that gets called when all diff --git a/parser/pbf/process_test.go b/parser/pbf/process_test.go index cf5a6ad..7e4e737 100644 --- a/parser/pbf/process_test.go +++ b/parser/pbf/process_test.go @@ -55,10 +55,6 @@ func TestParser(t *testing.T) { }() p.Parse() - close(nodes) - close(coords) - close(ways) - close(relations) wg.Wait() if numCoords != 17233 { @@ -75,6 +71,35 @@ func TestParser(t *testing.T) { } } +func TestParseCoords(t *testing.T) { + coords := make(chan []element.Node) + + pbf, err := Open("monaco-20150428.osm.pbf") + if err != nil { + t.Fatal(err) + } + p := NewParser(pbf, coords, nil, nil, nil) + + wg := sync.WaitGroup{} + + var numCoords int64 + + go func() { + wg.Add(1) + for nd := range coords { + numCoords += int64(len(nd)) + } + wg.Done() + }() + + p.Parse() + wg.Wait() + + if numCoords != 17233 { + t.Error("parsed an unexpected number of coords:", numCoords) + } +} + func TestParserNotify(t *testing.T) { nodes := make(chan []element.Node) coords := make(chan []element.Node) @@ -143,10 +168,6 @@ func TestParserNotify(t *testing.T) { }() p.Parse() - close(nodes) - close(coords) - close(ways) - close(relations) wg.Wait() if numCoords != 17233 { diff --git a/reader/reader.go b/reader/reader.go index 4115b74..6d8546c 100644 --- a/reader/reader.go +++ b/reader/reader.go @@ -239,9 +239,5 @@ func ReadPbf(cache *osmcache.OSMCache, progress *stats.Statistics, } parser.Parse() - close(relations) - close(ways) - close(nodes) - close(coords) waitWriter.Wait() }