lang: gapi, unification: Shutdown unification quickly when asked

This is a bit of a hack until we improve the GAPI a bit, but will let us
shut down type unification a bit faster if we want to interrupt a long
running operation. Hopefully our future algorthmic performance
improvements will obliviate the need for this to be a common issue.
This commit is contained in:
James Shubin
2024-03-22 03:21:15 -04:00
parent c4b14ac40d
commit 89784e86bd
3 changed files with 19 additions and 1 deletions

View File

@@ -503,6 +503,16 @@ func (obj *GAPI) Graph() (*pgraph.Graph, error) {
// Next returns nil errors every time there could be a new graph.
func (obj *GAPI) Next() chan gapi.Next {
// TODO: This ctx stuff is temporary until we improve the Next() API.
ctx, cancel := context.WithCancel(context.Background())
obj.wg.Add(1)
go func() {
defer obj.wg.Done()
select {
case <-obj.closeChan:
cancel() // close the ctx to unblock type unification
}
}()
ch := make(chan gapi.Next)
obj.wg.Add(1)
go func() {
@@ -553,7 +563,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(context.TODO()); e != nil { // init the new one!
} else if e := obj.LangInit(ctx); e != nil { // init the new one!
err = e // pass through the err
// Always run LangClose after LangInit