context passing
This commit is contained in:
+8
-3
@@ -1,6 +1,7 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"image"
|
||||
"sync"
|
||||
|
||||
@@ -21,6 +22,8 @@ type client struct {
|
||||
app fyne.App
|
||||
window fyne.Window
|
||||
|
||||
loadReportFunc func(uint)
|
||||
|
||||
world *world.World
|
||||
drawer *world.GGDrawer
|
||||
raster *canvas.Raster
|
||||
@@ -63,7 +66,7 @@ type client struct {
|
||||
hits []world.Hit
|
||||
}
|
||||
|
||||
func NewClient(conn connector.UIConnector, app fyne.App, settings mc.Settings) (mc.Client, error) {
|
||||
func NewClient(ctx context.Context, conn connector.UIConnector, app fyne.App, settings mc.Settings) (mc.Client, error) {
|
||||
e := &client{
|
||||
conn: conn,
|
||||
app: app,
|
||||
@@ -77,6 +80,8 @@ func NewClient(conn connector.UIConnector, app fyne.App, settings mc.Settings) (
|
||||
hits: make([]world.Hit, 5),
|
||||
}
|
||||
|
||||
e.loadReportFunc = func(t uint) { e.loadReport(ctx, t) }
|
||||
|
||||
e.drawer = &world.GGDrawer{DC: nil}
|
||||
|
||||
e.raster = canvas.NewRaster(func(wPx, hPx int) image.Image {
|
||||
@@ -96,8 +101,8 @@ func NewClient(conn connector.UIConnector, app fyne.App, settings mc.Settings) (
|
||||
return e, nil
|
||||
}
|
||||
|
||||
func (e *client) loadReport(t uint) {
|
||||
e.conn.FetchReport("GAME_ID", t, func(r report.Report, err error) {
|
||||
func (e *client) loadReport(ctx context.Context, t uint) {
|
||||
e.conn.FetchReport(ctx, "GAME_ID", t, func(r report.Report, err error) {
|
||||
if err != nil {
|
||||
e.handlerError(err)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user