Share hand cursors with pub/sub
Bob subscribes to the exact subject checkers/table/cursor. Rosie publishes her hand position (6.2, 3.1). The publisher gets a delivery count. Bob gets the subject, a sequence number, the data, and a count of dropped deliveries. The test checks that the board still has the same position.
Subscribe before publishing. Someone joining later waits for the next cursor position. This works for a moving pointer because a fresh position supersedes an older one. A player who misses a turn notification reads the board.
Go example
func publish(t *testing.T, ctx context.Context, db *stardust.Database) {
type cursor struct {
Player string `json:"player"`
X float64 `json:"x"`
Y float64 `json:"y"`
}
watch := must(stardust.SubscribeEvents[cursor](db, "checkers/table/cursor"))
defer watch.Close()
before := board(db)
hand := cursor{"rosie", 6.2, 3.1}
delivery := must(stardust.Publish(db, "checkers/table/cursor", hand))
event := must(watch.Next(ctx))
if delivery.Delivered != 1 || event.Data != hand || event.Dropped != 0 || !slices.Equal(board(db), before) {
t.Fatal("cursor delivery changed or missed the position", delivery, event)
}
}