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) {
type jobWriter struct {
job *xzc
wFn func() (bool, error)
canceled *bool
wFn func() (bool, error)
}
jWs := make(chan jobWriter)
asyncWrite := make(chan struct{})
go func() {
defer close(asyncWrite)
for jw := range jWs {
updated, err := jw.wFn()
if err != nil {
*jw.canceled = true
log.Printf("WARN: writing tile failed: %v.\n", err)
}
if !updated {
jw.job.canceled = true
*jw.canceled = true
}
}
}()
defer func() {
close(jWs)
btc.Close()
done.Done()
}()
@ -431,6 +435,13 @@ func (tu *tileUpdater) updateBaseTiles(
job.canceled = true
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
}