Skip to content

Commit

Permalink
lang: funcs: structs: Add Call method for const
Browse files Browse the repository at this point in the history
  • Loading branch information
purpleidea committed Dec 8, 2024
1 parent 28f5b83 commit e9dbb7b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lang/funcs/structs/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,25 @@ func (obj *ConstFunc) Init(init *interfaces.Init) error {

// Stream returns the single value that this const has, and then closes.
func (obj *ConstFunc) Stream(ctx context.Context) error {
value, err := obj.Call(ctx, nil)
if err != nil {
return err
}
select {
case obj.init.Output <- obj.Value:
case obj.init.Output <- value:
// pass
case <-ctx.Done():
return nil
}
close(obj.init.Output) // signal that we're done sending
return nil
}

// Call this function with the input args and return the value if it is possible
// to do so at this time.
func (obj *ConstFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) {
if obj.Value == nil {
return nil, fmt.Errorf("no value available from const")
}
return obj.Value, nil
}

0 comments on commit e9dbb7b

Please sign in to comment.