MCPcopy Create free account
hub / github.com/cel-expr/cel-go / ObserveExec

Method ObserveExec

interpreter/interpretable.go:188–205  ·  view source on GitHub ↗

ObserveExec evaluates an interpretable and performs per-evaluation state-tracking. This method is concurrency safe and the expectation is that the observer function will use a switch statement to determine the type of the state which has been reported back from the call.

(frame *ExecutionFrame, observer func(any))

Source from the content-addressed store, hash-verified

186// This method is concurrency safe and the expectation is that the observer function will use
187// a switch statement to determine the type of the state which has been reported back from the call.
188func (oi *ObservableInterpretable) ObserveExec(frame *ExecutionFrame, observer func(any)) ref.Val {
189 // Initialize the state needed for the observers to function.
190 for _, obs := range oi.observers {
191 state, err := obs.InitState(frame)
192 if err != nil {
193 return types.WrapErr(err)
194 }
195 // Provide an initial reference to the state to ensure state is available
196 // even in cases of interrupting errors generated during evaluation.
197 observer(state)
198 }
199 result := oi.InterpretableV2.Exec(frame)
200 // Get the state which needs to be reported back as having been observed.
201 for _, obs := range oi.observers {
202 observer(obs.GetState(frame))
203 }
204 return result
205}
206
207// EvalActivation runs an InterpretableV2 Exec method safely with any Activation,
208// wrapping it in a pooled ExecutionFrame if needed and releasing it after execution.

Callers 5

ExecMethod · 0.95
ObserveEvalMethod · 0.95
EvalMethod · 0.80
ConcurrentEvalMethod · 0.80

Calls 4

WrapErrFunction · 0.92
InitStateMethod · 0.65
ExecMethod · 0.65
GetStateMethod · 0.65

Tested by 1