diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-05 03:57:21 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-05 03:57:21 +0900 |
| commit | 296aa3f8a145a8fbc08db9f5b1d45fe6f72a38a4 (patch) | |
| tree | 11180e08e96e1adb492b3aa52d32edd79a669711 /backend/game/hub.go | |
| parent | 9ff9c151e5defd9eed5cba3c88bc341b4360d09c (diff) | |
| download | iosdc-japan-2024-albatross-296aa3f8a145a8fbc08db9f5b1d45fe6f72a38a4.tar.gz iosdc-japan-2024-albatross-296aa3f8a145a8fbc08db9f5b1d45fe6f72a38a4.tar.zst iosdc-japan-2024-albatross-296aa3f8a145a8fbc08db9f5b1d45fe6f72a38a4.zip | |
feat: implement task queue
Diffstat (limited to 'backend/game/hub.go')
| -rw-r--r-- | backend/game/hub.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/backend/game/hub.go b/backend/game/hub.go index 70bf71f..a44bce0 100644 --- a/backend/game/hub.go +++ b/backend/game/hub.go @@ -11,6 +11,7 @@ import ( "github.com/nsfisis/iosdc-japan-2024-albatross/backend/api" "github.com/nsfisis/iosdc-japan-2024-albatross/backend/db" + "github.com/nsfisis/iosdc-japan-2024-albatross/backend/taskqueue" ) type playerClientState int @@ -25,6 +26,7 @@ type gameHub struct { ctx context.Context game *game q *db.Queries + taskQueue *taskqueue.Queue players map[*playerClient]playerClientState registerPlayer chan *playerClient unregisterPlayer chan *playerClient @@ -34,11 +36,12 @@ type gameHub struct { unregisterWatcher chan *watcherClient } -func newGameHub(ctx context.Context, game *game, q *db.Queries) *gameHub { +func newGameHub(ctx context.Context, game *game, q *db.Queries, taskQueue *taskqueue.Queue) *gameHub { return &gameHub{ ctx: ctx, game: game, q: q, + taskQueue: taskQueue, players: make(map[*playerClient]playerClientState), registerPlayer: make(chan *playerClient), unregisterPlayer: make(chan *playerClient), @@ -258,14 +261,16 @@ func (hub *gameHub) closeWatcherClient(watcher *watcherClient) { } type GameHubs struct { - hubs map[int]*gameHub - q *db.Queries + hubs map[int]*gameHub + q *db.Queries + taskQueue *taskqueue.Queue } -func NewGameHubs(q *db.Queries) *GameHubs { +func NewGameHubs(q *db.Queries, taskQueue *taskqueue.Queue) *GameHubs { return &GameHubs{ - hubs: make(map[int]*gameHub), - q: q, + hubs: make(map[int]*gameHub), + q: q, + taskQueue: taskQueue, } } @@ -313,7 +318,7 @@ func (hubs *GameHubs) RestoreFromDB(ctx context.Context) error { startedAt: startedAt, problem: problem_, playerCount: len(playerRows), - }, hubs.q) + }, hubs.q, hubs.taskQueue) } return nil } |
