lang: funcs: Send empty values when appropriate

I seem to have forgotten to differentiate between the empty string and
no data because the zero value for the stored result was the empty
string. This turns it into a pointer so that we don't block the function
engine if a template or one of the other patched functions sends an
empty string as the first value.
This commit is contained in:
James Shubin
2019-12-30 12:35:08 -05:00
parent ff20e67d07
commit 762c53fb8d
10 changed files with 39 additions and 32 deletions

View File

@@ -40,8 +40,8 @@ type ReadFileFunc struct {
data *interfaces.FuncData
last types.Value // last value received to use for diff
filename string // the active filename
result string // last calculated output
filename string // the active filename
result *string // last calculated output
closeChan chan struct{}
}
@@ -139,10 +139,10 @@ func (obj *ReadFileFunc) Stream() error {
result := string(content) // convert to string
if obj.result == result {
if obj.result != nil && *obj.result == result {
continue // result didn't change
}
obj.result = result // store new result
obj.result = &result // store new result
case <-obj.closeChan:
return nil
@@ -150,7 +150,7 @@ func (obj *ReadFileFunc) Stream() error {
select {
case obj.init.Output <- &types.StrValue{
V: obj.result,
V: *obj.result,
}:
case <-obj.closeChan:
return nil