forked from MTSR/mapserver
worker
This commit is contained in:
parent
03598d4960
commit
b090d81f47
40
mapblockrenderer/worker.go
Normal file
40
mapblockrenderer/worker.go
Normal file
@ -0,0 +1,40 @@
|
||||
package mapblockrenderer
|
||||
|
||||
import (
|
||||
"time"
|
||||
"bytes"
|
||||
"mapserver/coords"
|
||||
"image/png"
|
||||
|
||||
)
|
||||
|
||||
type JobData struct {
|
||||
Pos1, Pos2 coords.MapBlockCoords
|
||||
X, Z int
|
||||
}
|
||||
|
||||
type JobResult struct {
|
||||
Data *bytes.Buffer
|
||||
Duration time.Duration
|
||||
Job JobData
|
||||
}
|
||||
|
||||
func worker(r *MapBlockRenderer, jobs <-chan JobData, results chan<- JobResult) {
|
||||
for d := range jobs {
|
||||
img, _ := r.Render(d.Pos1, d.Pos2)
|
||||
|
||||
w := new(bytes.Buffer)
|
||||
start := time.Now()
|
||||
|
||||
if img != nil {
|
||||
png.Encode(w, img)
|
||||
}
|
||||
|
||||
t := time.Now()
|
||||
elapsed := t.Sub(start)
|
||||
|
||||
res := JobResult{Data: w, Duration: elapsed, Job: d}
|
||||
results <- res
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user