Added correct Type for simple_thread

graph-rework-2
noah metz 2023-07-09 16:03:42 -06:00
parent b846bbb812
commit 269e7a57e2
4 changed files with 14 additions and 8 deletions

@ -191,11 +191,11 @@ func NewContext(db * badger.DB, log Logger, extra_nodes map[string]NodeLoadFunc,
if err != nil {
panic(err)
}
/*err := ctx.RegisterNodeType("simple_thread", LoadSimpleThread)
err = ctx.RegisterNodeType("simple_thread", LoadSimpleThread)
if err != nil {
panic(err)
}
err := ctx.RegisterNodeType("gql_thread", LoadGQLThread)
/*err := ctx.RegisterNodeType("gql_thread", LoadGQLThread)
if err != nil {
panic(err)
}*/

@ -7,7 +7,7 @@ import (
// A Lockable represents a Node that can be locked and hold other Nodes locks
type Lockable interface {
// All Lockable's are nodes
// All Lockables are nodes
Node
//// State Modification Function
// Record that lockable was returned to it's owner and is no longer held by this Node
@ -214,6 +214,10 @@ func (lockable * SimpleLockable) CanUnlock(new_owner Lockable) error {
// lockable must already be locked for read
func (lockable * SimpleLockable) Signal(ctx *Context, signal GraphSignal, nodes NodeMap) error {
err := lockable.GraphNode.Signal(ctx, signal, nodes)
if err != nil {
return err
}
if signal.Direction() == Up {
// Child->Parent, lockable updates dependency lockables
owner_sent := false
@ -253,8 +257,7 @@ func (lockable * SimpleLockable) Signal(ctx *Context, signal GraphSignal, nodes
} else {
panic(fmt.Sprintf("Invalid signal direction: %d", signal.Direction()))
}
// Run the base update function, and return
return lockable.GraphNode.Signal(ctx, signal, nodes)
return nil
}
// Requires lockable and requirement's states to be locked for write

@ -267,6 +267,10 @@ type SimpleThread struct {
timeout_action string
}
func (thread * SimpleThread) Type() NodeType {
return NodeType("simple_thread")
}
func (thread * SimpleThread) Serialize() ([]byte, error) {
thread_json := NewSimpleThreadJSON(thread)
return json.MarshalIndent(&thread_json, "", " ")

@ -4,7 +4,6 @@ import (
"testing"
"time"
"fmt"
"encoding/json"
)
func TestNewThread(t * testing.T) {
@ -87,7 +86,7 @@ func TestThreadDBLoad(t * testing.T) {
fatalErr(t, err)
err = UseStates(ctx, []Node{t1}, func(nodes NodeMap) error {
ser, err := json.MarshalIndent(nodes[t1.ID()], "", " ")
ser, err := t1.Serialize()
fmt.Printf("\n%s\n\n", ser)
return err
})
@ -96,7 +95,7 @@ func TestThreadDBLoad(t * testing.T) {
fatalErr(t, err)
err = UseStates(ctx, []Node{t1_loaded}, func(nodes NodeMap) error {
ser, err := json.MarshalIndent(nodes[t1_loaded.ID()], "", " ")
ser, err := t1_loaded.Serialize()
fmt.Printf("\n%s\n\n", ser)
return err
})