lang: interfaces, funcs: Port Func API to new Stream signature

This removes the `Close() error` and replaces it with a more modern
Stream API that takes a context. This removes boilerplate and makes
integration with concurrent code easier. The only downside is that there
isn't an explicit cleanup step, but only one function was even using
that and it was possible to switch it to a defer in Stream.

This also renames the functions from polyfunc to just func which we
determine by API not naming.
This commit is contained in:
James Shubin
2023-05-28 16:20:42 -04:00
parent 6a06f7b2ea
commit b134c4b778
41 changed files with 276 additions and 540 deletions

View File

@@ -18,6 +18,7 @@
package facts
import (
"context"
"fmt"
"github.com/purpleidea/mgmt/lang/interfaces"
@@ -75,11 +76,6 @@ func (obj *FactFunc) Init(init *interfaces.Init) error {
}
// Stream returns the changing values that this function has over time.
func (obj *FactFunc) Stream() error {
return obj.Fact.Stream()
}
// Close runs some shutdown code for this function and turns off the stream.
func (obj *FactFunc) Close() error {
return obj.Fact.Close()
func (obj *FactFunc) Stream(ctx context.Context) error {
return obj.Fact.Stream(ctx)
}