Files
notarius/internal/framework/pipeline/synchronized_collaborators.go

37 lines
948 B
Go

package pipeline
import "sync"
type lockedDebugRecorder struct {
inner DebugRecorder
mu sync.Mutex
}
func synchronizedDebugRecorder(inner DebugRecorder) DebugRecorder {
if _, ok := inner.(*lockedDebugRecorder); ok {
return inner
}
return &lockedDebugRecorder{inner: inner}
}
// SynchronizedDebugRecorder serializes access when a recorder is shared by
// pipeline operations and construction-injected LLM clients.
func SynchronizedDebugRecorder(inner DebugRecorder) DebugRecorder {
return synchronizedDebugRecorder(inner)
}
func (r *lockedDebugRecorder) Enabled() bool {
r.mu.Lock()
defer r.mu.Unlock()
return r.inner.Enabled()
}
func (r *lockedDebugRecorder) WriteJSON(name string, payload any) error {
r.mu.Lock()
defer r.mu.Unlock()
return r.inner.WriteJSON(name, payload)
}
func (r *lockedDebugRecorder) WriteBytes(name string, data []byte) error {
r.mu.Lock()
defer r.mu.Unlock()
return r.inner.WriteBytes(name, data)
}