Simplify chat subscription API #9

Merged
ryan merged 1 commits from refactor/chat-subscribe-messages into main 2026-03-03 19:54:21 +00:00
Owner

Summary

  • Room.Subscribe() now returns <-chan Message instead of chan *nats.Msg
  • Room handles NATS subscription and JSON parsing internally
  • Callers no longer need to call Receive() separately
  • Receive() renamed to receive() (unexported)

Before:

chatCh, chatSub, err := room.Subscribe()
defer chatSub.Unsubscribe()
// ...
case msg := <-chatCh:
    chatMsg, _ := room.Receive(msg.Data)

After:

chatCh, cleanup := room.Subscribe()
defer cleanup()
// ...
case chatMsg := <-chatCh:
    // chatMsg is already a parsed Message
## Summary - `Room.Subscribe()` now returns `<-chan Message` instead of `chan *nats.Msg` - Room handles NATS subscription and JSON parsing internally - Callers no longer need to call `Receive()` separately - `Receive()` renamed to `receive()` (unexported) Before: ```go chatCh, chatSub, err := room.Subscribe() defer chatSub.Unsubscribe() // ... case msg := <-chatCh: chatMsg, _ := room.Receive(msg.Data) ``` After: ```go chatCh, cleanup := room.Subscribe() defer cleanup() // ... case chatMsg := <-chatCh: // chatMsg is already a parsed Message ```
ryan added 1 commit 2026-03-03 19:46:03 +00:00
refactor: simplify chat subscription API
All checks were successful
CI / Deploy / test (pull_request) Successful in 14s
CI / Deploy / lint (pull_request) Successful in 25s
CI / Deploy / deploy (pull_request) Has been skipped
bcb1fa3872
Room.Subscribe() now returns a channel of parsed Message structs
instead of raw NATS messages. The room handles NATS subscription
and message parsing internally, so callers no longer need to call
Receive() separately.
ryan merged commit ffbff8cca5 into main 2026-03-03 19:54:21 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ryan/games#9