@@ -5,26 +5,28 @@ import (
8+// bufferSize is the per-subscriber channel capacity for any broker
9+// created via NewBroker. Publish is non-blocking, so a full buffer
10+// silently drops events; sized to cover a long streaming assistant
11+// turn (~one UpdatedEvent per token) even under TUI render stalls.
8−const bufferSize = 64
12+const bufferSize = 4096
10type Broker[T any] struct {
14type Broker[T any] struct {
11 subs map[chan Event[T]]struct{}
15 subs map[chan Event[T]]struct{}
12 mu sync.RWMutex
16 mu sync.RWMutex
13 done chan struct{}
17 done chan struct{}
14 subCount int
18 subCount int
16 channelBufferSize int
19 channelBufferSize int
19func NewBroker[T any]() *Broker[T] {
22func NewBroker[T any]() *Broker[T] {
20− return NewBrokerWithOptions[T](bufferSize, 1000)
23+ return NewBrokerWithOptions[T](bufferSize)
23−func NewBrokerWithOptions[T any](channelBufferSize, maxEvents int) *Broker[T] {
26+func NewBrokerWithOptions[T any](channelBufferSize int) *Broker[T] {
24 return &Broker[T]{
27 return &Broker[T]{
25 subs: make(map[chan Event[T]]struct{}),
28 subs: make(map[chan Event[T]]struct{}),
26 done: make(chan struct{}),
29 done: make(chan struct{}),
27− maxEvents: maxEvents,
28 channelBufferSize: channelBufferSize,
30 channelBufferSize: channelBufferSize,