Select execution observers from context
This commit is contained in:
@@ -17,6 +17,18 @@ import (
|
||||
// event, and Promptkit keeps no asynchronous queue or durable history.
|
||||
type ExecutionObserver func(ExecutionEvent)
|
||||
|
||||
// WithExecutionObserver adds an observer to executions using the returned
|
||||
// context. Inherited observers run before the newly added observer. A nil
|
||||
// observer leaves the context unchanged.
|
||||
func WithExecutionObserver(ctx context.Context, observer ExecutionObserver) context.Context {
|
||||
if observer == nil {
|
||||
return ctx
|
||||
}
|
||||
return observation.WithObserver(ctx, func(event domain.ExecutionEvent) {
|
||||
observer(fromDomainExecutionEvent(event))
|
||||
})
|
||||
}
|
||||
|
||||
// ComposeObservers returns a synchronous ordered fan-out of non-nil observers.
|
||||
// It copies the input slice; a panic propagates and prevents later callbacks.
|
||||
func ComposeObservers(observers ...ExecutionObserver) ExecutionObserver {
|
||||
|
||||
Reference in New Issue
Block a user