Wait until all tiles are written out or are cancelled.

This commit is contained in:
Sascha L. Teichmann 2022-03-01 21:02:08 +01:00
parent c507663826
commit da2b327985
1 changed files with 16 additions and 5 deletions

View File

@ -400,26 +400,30 @@ func (tu *tileUpdater) updateBaseTiles(
update common.BaseTileUpdateFunc) { update common.BaseTileUpdateFunc) {
type jobWriter struct { type jobWriter struct {
job *xzc canceled *bool
wFn func() (bool, error) wFn func() (bool, error)
} }
jWs := make(chan jobWriter) jWs := make(chan jobWriter)
asyncWrite := make(chan struct{})
go func() { go func() {
defer close(asyncWrite)
for jw := range jWs { for jw := range jWs {
updated, err := jw.wFn() updated, err := jw.wFn()
if err != nil { if err != nil {
*jw.canceled = true
log.Printf("WARN: writing tile failed: %v.\n", err) log.Printf("WARN: writing tile failed: %v.\n", err)
} }
if !updated { if !updated {
jw.job.canceled = true *jw.canceled = true
} }
} }
}() }()
defer func() { defer func() {
close(jWs)
btc.Close() btc.Close()
done.Done() done.Done()
}() }()
@ -431,6 +435,13 @@ func (tu *tileUpdater) updateBaseTiles(
job.canceled = true job.canceled = true
continue continue
} }
jWs <- jobWriter{job, btc.WriteFunc(int(job.X), int(job.Z), update)} jWs <- jobWriter{
&job.canceled,
btc.WriteFunc(int(job.X), int(job.Z), update),
}
} }
close(jWs)
// Wait until all tiles are written.
<-asyncWrite
} }