lang: funcs: structs: Add Call method for const
This commit is contained in:
@@ -94,8 +94,12 @@ func (obj *ConstFunc) Init(init *interfaces.Init) error {
|
|||||||
|
|
||||||
// Stream returns the single value that this const has, and then closes.
|
// Stream returns the single value that this const has, and then closes.
|
||||||
func (obj *ConstFunc) Stream(ctx context.Context) error {
|
func (obj *ConstFunc) Stream(ctx context.Context) error {
|
||||||
|
value, err := obj.Call(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
select {
|
select {
|
||||||
case obj.init.Output <- obj.Value:
|
case obj.init.Output <- value:
|
||||||
// pass
|
// pass
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil
|
return nil
|
||||||
@@ -103,3 +107,12 @@ func (obj *ConstFunc) Stream(ctx context.Context) error {
|
|||||||
close(obj.init.Output) // signal that we're done sending
|
close(obj.init.Output) // signal that we're done sending
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user