Add in-process event bus with ring buffer for workflow event broadcasting

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/claude-agent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
Alexander
2026-05-11 15:53:43 +02:00
parent f52e9abb0a
commit 7582279077
4 changed files with 449 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
package eventbus
import "sync"
type RingBuffer[T any] struct {
mu sync.Mutex
buf []T
head int
tail int
count int
cap int
}
func NewRingBuffer[T any](capacity int) *RingBuffer[T] {
return &RingBuffer[T]{
buf: make([]T, capacity),
cap: capacity,
}
}
func (r *RingBuffer[T]) Push(item T) {
r.mu.Lock()
defer r.mu.Unlock()
r.buf[r.head] = item
r.head = (r.head + 1) % r.cap
if r.count == r.cap {
r.tail = (r.tail + 1) % r.cap
} else {
r.count++
}
}
func (r *RingBuffer[T]) Pop() (T, bool) {
r.mu.Lock()
defer r.mu.Unlock()
var zero T
if r.count == 0 {
return zero, false
}
item := r.buf[r.tail]
r.buf[r.tail] = zero
r.tail = (r.tail + 1) % r.cap
r.count--
return item, true
}
func (r *RingBuffer[T]) Len() int {
r.mu.Lock()
defer r.mu.Unlock()
return r.count
}