Select execution observers from context
This commit is contained in:
@@ -195,6 +195,22 @@ func (r *Recorder) deliver(event domain.ExecutionEvent) {
|
||||
|
||||
type contextKey struct{}
|
||||
|
||||
type observerKey struct{}
|
||||
|
||||
// WithObserver adds an observer to the inherited contextual selection.
|
||||
func WithObserver(ctx context.Context, observer domain.ExecutionObserver) context.Context {
|
||||
if observer == nil {
|
||||
return ctx
|
||||
}
|
||||
return context.WithValue(ctx, observerKey{}, Compose(ObserverFromContext(ctx), observer))
|
||||
}
|
||||
|
||||
// ObserverFromContext returns the contextual observer selection, if any.
|
||||
func ObserverFromContext(ctx context.Context) domain.ExecutionObserver {
|
||||
observer, _ := ctx.Value(observerKey{}).(domain.ExecutionObserver)
|
||||
return observer
|
||||
}
|
||||
|
||||
// WithoutExecutionState starts a public operation without inheriting another
|
||||
// invocation's recorder or prepared-claim sink. Other context values and all
|
||||
// cancellation/deadline behavior remain with the caller's context.
|
||||
|
||||
Reference in New Issue
Block a user