@@ -5,26 +5,28 @@ import (
55 "sync"
66)
77
8โconst bufferSize = 64
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.
12+const bufferSize = 4096
913
1014type Broker[T any] struct {
1115 subs map[chan Event[T]]struct{}
1216 mu sync.RWMutex
1317 done chan struct{}
1418 subCount int
15โ maxEvents int
1619 channelBufferSize int
1720}
1821
1922func NewBroker[T any]() *Broker[T] {
20โ return NewBrokerWithOptions[T](bufferSize, 1000)
23+ return NewBrokerWithOptions[T](bufferSize)
2124}
2225
23โfunc NewBrokerWithOptions[T any](channelBufferSize, maxEvents int) *Broker[T] {
26+func NewBrokerWithOptions[T any](channelBufferSize int) *Broker[T] {
2427 return &Broker[T]{
2528 subs: make(map[chan Event[T]]struct{}),
2629 done: make(chan struct{}),
27โ maxEvents: maxEvents,
2830 channelBufferSize: channelBufferSize,
2931 }
3032}