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

@@ -89,6 +89,8 @@ func (obj CPUCountFact) Stream() error {
closeChan := make(chan struct{}) // channel to unblock selects in goroutine
defer close(closeChan)
var once bool // did we send at least once?
// wait for kernel to poke us about new device changes on the system
wg.Add(1)
go func() {
@@ -121,6 +123,8 @@ func (obj CPUCountFact) Stream() error {
if err != nil {
obj.init.Logf("Could not get initial CPU count. Setting to zero.")
}
// TODO: would we rather error instead of sending zero?
case event, ok := <-eventChan:
if !ok {
continue
@@ -142,7 +146,7 @@ func (obj CPUCountFact) Stream() error {
return nil
}
if newCount == cpuCount {
if once && newCount == cpuCount {
continue
}
cpuCount = newCount
@@ -151,6 +155,7 @@ func (obj CPUCountFact) Stream() error {
case obj.init.Output <- &types.IntValue{
V: cpuCount,
}:
once = true
// send
case <-obj.closeChan:
return nil