diff options
| author | adamdottv <[email protected]> | 2025-05-06 14:22:37 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-05-06 14:22:37 -0500 |
| commit | b638dafe5fb2b6fcdd6d9b64502a7808f3e81eb5 (patch) | |
| tree | 6f6729fcc08a042812b642ef6acb8fc4d9db9b9b /internal/pubsub | |
| parent | e387b1f16c2a7630c7f2ea29b39d4f50b1760ad7 (diff) | |
| download | opencode-b638dafe5fb2b6fcdd6d9b64502a7808f3e81eb5.tar.gz opencode-b638dafe5fb2b6fcdd6d9b64502a7808f3e81eb5.zip | |
feat: better logs page
Diffstat (limited to 'internal/pubsub')
| -rw-r--r-- | internal/pubsub/broker.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/internal/pubsub/broker.go b/internal/pubsub/broker.go index 88a59f60a..5aadd8ed5 100644 --- a/internal/pubsub/broker.go +++ b/internal/pubsub/broker.go @@ -5,7 +5,7 @@ import ( "sync" ) -const bufferSize = 64 +const bufferSize = 1000 type Broker[T any] struct { subs map[chan Event[T]]struct{} @@ -115,7 +115,23 @@ func (b *Broker[T]) Publish(t EventType, payload T) { for _, sub := range subscribers { select { case sub <- event: + // Successfully sent + case <-b.done: + // Broker is shutting down + return default: + // Channel is full, but we don't want to block + // Log this situation or consider other strategies + // For now, we'll create a new goroutine to ensure delivery + go func(ch chan Event[T], evt Event[T]) { + select { + case ch <- evt: + // Successfully sent + case <-b.done: + // Broker is shutting down + return + } + }(sub, event) } } } |
