diff --git a/engine/graph/engine.go b/engine/graph/engine.go index f15650be..e6b07560 100644 --- a/engine/graph/engine.go +++ b/engine/graph/engine.go @@ -191,7 +191,7 @@ func (obj *Engine) Commit() error { obj.waits[vertex] = &sync.WaitGroup{} obj.state[vertex] = &State{ - //Graph: obj.graph, // TODO: what happens if we swap the graph? + Graph: obj.graph, // Update if we swap the graph! Vertex: vertex, Program: obj.Program, @@ -329,14 +329,14 @@ func (obj *Engine) Commit() error { // the changes that we'd made to the previously primary graph. This is // because this function is meant to atomically swap the graphs safely. - // TODO: update all the `State` structs with the new Graph pointer - //for _, vertex := range obj.graph.Vertices() { - // state, exists := obj.state[vertex] - // if !exists { - // continue - // } - // state.Graph = obj.graph // update pointer to graph - //} + // Update all the `State` structs with the new Graph pointer. + for _, vertex := range obj.graph.Vertices() { + state, exists := obj.state[vertex] + if !exists { + continue + } + state.Graph = obj.graph // update pointer to graph + } return nil } diff --git a/engine/graph/state.go b/engine/graph/state.go index 251f48f3..742e8b4b 100644 --- a/engine/graph/state.go +++ b/engine/graph/state.go @@ -32,7 +32,7 @@ import ( // State stores some state about the resource it is mapped to. type State struct { // Graph is a pointer to the graph that this vertex is part of. - //Graph pgraph.Graph + Graph *pgraph.Graph // Vertex is the pointer in the graph that this state corresponds to. It // can be converted to a `Res` if necessary. @@ -190,6 +190,16 @@ func (obj *State) Init() error { return res.Recv() }, + // FIXME: pass in a safe, limited query func instead? + // TODO: not implemented, use FilteredGraph + //Graph: func() *pgraph.Graph { + // _, ok := obj.Vertex.(engine.CanGraphQueryRes) + // if !ok { + // panic("res does not support the GraphQuery trait") + // } + // return obj.Graph // we return in a func so it's fresh! + //}, + World: obj.World, VarDir: obj.varDir, diff --git a/engine/resources.go b/engine/resources.go index a9aec465..043a5e1e 100644 --- a/engine/resources.go +++ b/engine/resources.go @@ -120,6 +120,12 @@ type Init struct { // Other functionality: + // Graph is a function that returns the current graph. The returned + // value won't be valid after a graphsync so make sure to call this when + // you are about to use it, and discard it right after. + // FIXME: it might be better to offer a safer, more limited, GraphQuery? + //Graph func() *pgraph.Graph // TODO: not implemented, use FilteredGraph + // World provides a connection to the outside world. This is most often // used for communicating with the distributed database. World World