lang: Plumb the ctx deeper into the lang API

This commit is contained in:
James Shubin
2024-03-16 00:35:33 -04:00
parent 10319dd641
commit d6a6734b65
3 changed files with 12 additions and 12 deletions

View File

@@ -427,7 +427,7 @@ func (obj *GAPI) Init(data *gapi.Data) error {
}
// LangInit is a wrapper around the lang Init method.
func (obj *GAPI) LangInit() error {
func (obj *GAPI) LangInit(ctx context.Context) error {
if obj.lang != nil {
return nil // already ran init, close first!
}
@@ -456,7 +456,7 @@ func (obj *GAPI) LangInit() error {
obj.data.Logf(Name+": "+format, v...)
},
}
if err := lang.Init(); err != nil {
if err := lang.Init(ctx); err != nil {
return errwrap.Wrapf(err, "can't init the lang")
}
obj.lang = lang // once we can't fail, store the struct...
@@ -553,7 +553,7 @@ func (obj *GAPI) Next() chan gapi.Next {
// run up to these three but fail on err
if e := obj.LangClose(); e != nil { // close any old lang
err = e // pass through the err
} else if e := obj.LangInit(); e != nil { // init the new one!
} else if e := obj.LangInit(context.TODO()); e != nil { // init the new one!
err = e // pass through the err
// Always run LangClose after LangInit

View File

@@ -99,7 +99,7 @@ type Lang struct {
// NOTE: The trick is that we need to get the list of funcs to watch AND start
// watching them, *before* we pull their values, that way we'll know if they
// changed from the values we wanted.
func (obj *Lang) Init() error {
func (obj *Lang) Init(ctx context.Context) error {
if obj.Debug {
obj.Logf("input: %s", obj.Input)
tree, err := util.FsTree(obj.Fs, "/") // should look like gapi
@@ -232,7 +232,7 @@ func (obj *Lang) Init() error {
Debug: obj.Debug,
Logf: logf,
}
unifyErr := unifier.Unify(context.TODO())
unifyErr := unifier.Unify(ctx)
obj.Logf("type unification took: %s", time.Since(timing))
if unifyErr != nil {
return errwrap.Wrapf(unifyErr, "could not unify types")

View File

@@ -128,23 +128,23 @@ func runInterpret(t *testing.T, code string) (_ *pgraph.Graph, reterr error) {
}
logf("tree:\n%s", tree)
wg := &sync.WaitGroup{}
defer wg.Wait()
ctx, cancel := context.WithCancel(context.Background()) // TODO: get it from parent
defer cancel()
lang := &Lang{
Fs: fs,
Input: "/" + interfaces.MetadataFilename, // start path in fs
Debug: testing.Verbose(), // set via the -test.v flag to `go test`
Logf: logf,
}
if err := lang.Init(); err != nil {
if err := lang.Init(ctx); err != nil {
return nil, errwrap.Wrapf(err, "init failed")
}
defer lang.Cleanup()
wg := &sync.WaitGroup{}
defer wg.Wait()
ctx, cancel := context.WithCancel(context.Background()) // TODO: get it from parent
defer cancel()
wg.Add(1)
go func() {
defer wg.Done()