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

Method ObserveExec

interpreter/interpretable.go:179–196  ·  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

177// This method is concurrency safe and the expectation is that the observer function will use
178// a switch statement to determine the type of the state which has been reported back from the call.
179func (oi *ObservableInterpretable) ObserveExec(frame *ExecutionFrame, observer func(any)) ref.Val {
180 // Initialize the state needed for the observers to function.
181 for _, obs := range oi.observers {
182 state, err := obs.InitState(frame)
183 if err != nil {
184 return types.WrapErr(err)
185 }
186 // Provide an initial reference to the state to ensure state is available
187 // even in cases of interrupting errors generated during evaluation.
188 observer(state)
189 }
190 result := oi.InterpretableV2.Exec(frame)
191 // Get the state which needs to be reported back as having been observed.
192 for _, obs := range oi.observers {
193 observer(obs.GetState(frame))
194 }
195 return result
196}
197
198// AsFrame promotes an Activation to an ExecutionFrame.
199func AsFrame(a Activation) *ExecutionFrame {

Callers 4

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

Calls 4

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

Tested by

no test coverage detected