close channels in Parse
parent
132d938bb4
commit
dc4f320dd5
|
@ -49,14 +49,19 @@ func (p *parser) Parse() {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
p.wg.Wait()
|
p.wg.Wait()
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser) Wait() {
|
if p.nodes != nil {
|
||||||
p.wg.Wait()
|
close(p.nodes)
|
||||||
}
|
}
|
||||||
|
if p.coords != nil {
|
||||||
func (p *parser) Close() {
|
close(p.coords)
|
||||||
p.wg.Wait()
|
}
|
||||||
|
if p.ways != nil {
|
||||||
|
close(p.ways)
|
||||||
|
}
|
||||||
|
if p.relations != nil {
|
||||||
|
close(p.relations)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FinishedCoords registers a single function that gets called when all
|
// FinishedCoords registers a single function that gets called when all
|
||||||
|
|
|
@ -55,10 +55,6 @@ func TestParser(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
p.Parse()
|
p.Parse()
|
||||||
close(nodes)
|
|
||||||
close(coords)
|
|
||||||
close(ways)
|
|
||||||
close(relations)
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
if numCoords != 17233 {
|
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) {
|
func TestParserNotify(t *testing.T) {
|
||||||
nodes := make(chan []element.Node)
|
nodes := make(chan []element.Node)
|
||||||
coords := make(chan []element.Node)
|
coords := make(chan []element.Node)
|
||||||
|
@ -143,10 +168,6 @@ func TestParserNotify(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
p.Parse()
|
p.Parse()
|
||||||
close(nodes)
|
|
||||||
close(coords)
|
|
||||||
close(ways)
|
|
||||||
close(relations)
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
if numCoords != 17233 {
|
if numCoords != 17233 {
|
||||||
|
|
|
@ -239,9 +239,5 @@ func ReadPbf(cache *osmcache.OSMCache, progress *stats.Statistics,
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.Parse()
|
parser.Parse()
|
||||||
close(relations)
|
|
||||||
close(ways)
|
|
||||||
close(nodes)
|
|
||||||
close(coords)
|
|
||||||
waitWriter.Wait()
|
waitWriter.Wait()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue