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))
| 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. |
| 188 | func (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. |