Skip to content

Commit

Permalink
Fix race condition when running hub
Browse files Browse the repository at this point in the history
  • Loading branch information
System-Glitch committed Apr 29, 2024
1 parent 2d119f0 commit 4f913de
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions http/controller/chat/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Hub struct {
}

// NewHub create a new chat Hub.
func NewHub(server *goyave.Server) *Hub {
func NewHub() *Hub {
ctx, cancel := context.WithCancel(context.Background())
hub := &Hub{
broadcast: make(chan []byte, 256),
Expand All @@ -40,7 +40,6 @@ func NewHub(server *goyave.Server) *Hub {
ctx: ctx,
cancel: cancel,
}
hub.Init(server)
return hub
}

Expand Down
4 changes: 2 additions & 2 deletions http/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ func Register(server *goyave.Server, router *goyave.Router) {
router.GlobalMiddleware(&parse.Middleware{})
router.GlobalMiddleware(log.CombinedLogMiddleware())

hub := chat.NewHub(server)
go hub.Run()
hub := chat.NewHub()

router.Subrouter("/chat").Controller(websocket.New(hub))
go hub.Run()

resources := server.Service(service.Static).(*static.Service).FS()
router.Static(resources, "/", false)
Expand Down

0 comments on commit 4f913de

Please sign in to comment.