1
0
forked from MTSR/mapserver
mapserver/mapblockrenderer/worker.go

39 lines
598 B
Go
Raw Normal View History

2019-01-15 18:30:26 +03:00
package mapblockrenderer
import (
2019-01-16 18:15:50 +03:00
"bytes"
"image/png"
2023-12-29 18:00:11 +03:00
"mapserver/types"
2019-01-16 18:15:50 +03:00
"time"
2019-01-15 18:30:26 +03:00
)
type JobData struct {
2023-12-29 18:00:11 +03:00
Pos1, Pos2 *types.MapBlockCoords
2019-01-15 18:30:26 +03:00
}
type JobResult struct {
2019-01-16 18:15:50 +03:00
Data *bytes.Buffer
Duration time.Duration
Job JobData
2019-01-15 18:30:26 +03:00
}
2019-01-16 18:15:50 +03:00
func Worker(r *MapBlockRenderer, jobs <-chan JobData, results chan<- JobResult) {
2019-01-15 18:30:26 +03:00
for d := range jobs {
img, _ := r.Render(d.Pos1, d.Pos2)
2019-01-16 18:15:50 +03:00
w := new(bytes.Buffer)
start := time.Now()
2019-01-15 18:30:26 +03:00
if img != nil {
png.Encode(w, img)
}
2019-01-16 18:15:50 +03:00
t := time.Now()
elapsed := t.Sub(start)
2019-01-15 18:30:26 +03:00
2019-01-16 18:15:50 +03:00
res := JobResult{Data: w, Duration: elapsed, Job: d}
results <- res
2019-01-15 18:30:26 +03:00
}
}