diff --git a/lang/funcs/structs/const.go b/lang/funcs/structs/const.go index 3d61325fb..d5d1ab3f4 100644 --- a/lang/funcs/structs/const.go +++ b/lang/funcs/structs/const.go @@ -94,8 +94,12 @@ 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 @@ -103,3 +107,12 @@ func (obj *ConstFunc) Stream(ctx context.Context) error { 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 +}