Post calls the user-defined PostFunc.
(ctx *PfContext, prepResult any, execResult any)
| 487 | |
| 488 | // Post calls the user-defined PostFunc. |
| 489 | func (bn *BatchNode) Post(ctx *PfContext, prepResult any, execResult any) (string, error) { |
| 490 | // Type assertions needed as interface methods deal with 'any' |
| 491 | prepSlice, okPrep := prepResult.([]any) |
| 492 | if prepResult != nil && !okPrep { // Allow nil prepResult |
| 493 | return "", newPocketFlowError(fmt.Sprintf("Internal error: prepResult in BatchNode %T Post was not []any (%T)", bn, prepResult), nil) |
| 494 | } |
| 495 | |
| 496 | execSlice, okExec := execResult.([]any) |
| 497 | if execResult != nil && !okExec { // Allow nil execResult (e.g., if prep was empty) |
| 498 | return "", newPocketFlowError(fmt.Sprintf("Internal error: execResult in BatchNode %T Post was not []any (%T)", bn, execResult), nil) |
| 499 | } |
| 500 | // Ensure slices are not nil if they were originally nil/empty, matching Java behaviour somewhat |
| 501 | if prepSlice == nil { |
| 502 | prepSlice = []any{} |
| 503 | } |
| 504 | if execSlice == nil { |
| 505 | execSlice = []any{} |
| 506 | } |
| 507 | |
| 508 | if bn.PostFunc == nil { |
| 509 | return DefaultAction, nil |
| 510 | } |
| 511 | action, err := bn.PostFunc(ctx, bn.params, prepSlice, execSlice) |
| 512 | if err == nil && action == "" { |
| 513 | action = DefaultAction |
| 514 | } |
| 515 | return action, err |
| 516 | } |
| 517 | |
| 518 | func (bn *BatchNode) Run(ctx *PfContext) (string, error) { |
| 519 | if len(bn.successors) > 0 { |
no test coverage detected