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

39 lines
600 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"
"mapserver/coords"
"time"
2019-01-15 18:30:26 +03:00
)
type JobData struct {
2019-02-06 10:38:08 +03:00
Pos1, Pos2 *coords.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
}
}