engine: graph: Split SendRecv off from the engine

It can be used in more places if it's not tied to the engine struct.
This also changes the signature so that more information is returned.
This can be used for logging or other useful things. Of note, this
happens to be the same struct as already exists. It's used for
convenience since it happens to match up! Of course they're related.
This commit is contained in:
James Shubin
2024-01-20 03:12:29 -05:00
parent f68b34a485
commit e5a189b8c6
2 changed files with 46 additions and 35 deletions

View File

@@ -118,10 +118,13 @@ func (obj *Engine) Process(ctx context.Context, vertex pgraph.Vertex) error {
// connect any senders to receivers and detect if values changed
// this actually checks and sends into resource trees recursively...
if res, ok := vertex.(engine.RecvableRes); ok {
if updated, err := obj.SendRecv(res); err != nil {
if obj.Debug {
obj.Logf("SendRecv: %s", res) // receiving here
}
if updated, err := SendRecv(res); err != nil {
return errwrap.Wrapf(err, "could not SendRecv")
} else if len(updated) > 0 {
for r, m := range updated { // map[engine.RecvableRes]map[string]bool
for r, m := range updated { // map[engine.RecvableRes]map[string]*engine.Send
v, ok := r.(pgraph.Vertex)
if !ok {
continue
@@ -130,11 +133,12 @@ func (obj *Engine) Process(ctx context.Context, vertex pgraph.Vertex) error {
if !stateExists {
continue
}
for _, changed := range m {
if !changed {
for s, send := range m {
if !send.Changed {
continue
}
// if changed == true, at least one was updated
obj.Logf("Send/Recv: %v.%s -> %v.%s", send.Res, send.Key, r, s)
// if send.Changed == true, at least one was updated
// invalidate cache, mark as dirty
obj.state[v].setDirty()
//break // we might have more vertices now