Skip to content

Commit

Permalink
invoke: add way to retrieve return values of an invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisvisco committed Sep 1, 2023
1 parent 698b9d7 commit 9998705
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type invokeOptions struct {

// InvokeInfo provides information about an Invoke.
type InvokeInfo struct {
Inputs []*Input
Inputs []*Input
ReturnValues []*reflect.Value
}

// FillInvokeInfo is an InvokeOption that writes information on the types
Expand Down Expand Up @@ -161,6 +162,13 @@ func (s *Scope) Invoke(function interface{}, opts ...InvokeOption) (err error) {
if len(returned) == 0 {
return nil
}

if options.Info != nil {
options.Info.ReturnValues = make([]*reflect.Value, len(returned))
for i, v := range returned {
options.Info.ReturnValues[i] = &v
}
}
if last := returned[len(returned)-1]; isError(last.Type()) {
if err, _ := last.Interface().(error); err != nil {
return err
Expand Down

0 comments on commit 9998705

Please sign in to comment.