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))
| 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. |
| 179 | func (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. |
| 199 | func AsFrame(a Activation) *ExecutionFrame { |