Add an in-process post event bus (#13)
CI / test (push) Successful in 6m16s

Handlers emit PostCreated and PostUpdated after a successful write. Store writes do not publish, and hidden roots are skipped.

Reviewed-on: #13
Co-authored-by: codegirl-007 <s.raide@gmail.com>
This commit was merged in pull request #13.
This commit is contained in:
2026-08-29 18:24:13 +00:00
committed by codegirl007
parent 19fea892f3
commit 911355ae35
10 changed files with 600 additions and 2 deletions
+44
View File
@@ -0,0 +1,44 @@
package events
import (
"context"
"sync"
)
// Recording is a test Publisher that records events synchronously.
type Recording struct {
mu sync.Mutex
evs []any
}
// Publish appends ev.
func (r *Recording) Publish(_ context.Context, ev any) {
if r == nil {
return
}
r.mu.Lock()
defer r.mu.Unlock()
r.evs = append(r.evs, ev)
}
// Len returns the number of recorded events.
func (r *Recording) Len() int {
if r == nil {
return 0
}
r.mu.Lock()
defer r.mu.Unlock()
return len(r.evs)
}
// Snapshot returns a copy of recorded events.
func (r *Recording) Snapshot() []any {
if r == nil {
return nil
}
r.mu.Lock()
defer r.mu.Unlock()
out := make([]any, len(r.evs))
copy(out, r.evs)
return out
}