package console import ( "sync" "github.com/novox/mesh-tools/node-tools/internal/bus" ) // busSource is a Source over a bus connection's own states, which a test's fixture mesh fills: the console's tests stand a // membership that reads the four states beside it, where the tool runner itself holds first views (firstview.Views). type busSource struct{ conn *bus.Conn } func (b busSource) State(name string) (map[string][]byte, error) { var mu sync.Mutex keys := map[string][]byte{} stop, err := b.conn.StateWatch(b.conn.Credential().Module, name, "", func(c bus.StateChange) error { if c.Current && c.Op == "put" { mu.Lock() keys[c.Key] = c.Value mu.Unlock() } return nil }) if err != nil { return nil, err } stop() mu.Lock() defer mu.Unlock() return keys, nil } func (b busSource) Entry(name, key string) ([]byte, error) { entry, err := b.conn.StateGet(b.conn.Credential().Module, name, key) if err != nil || entry == nil { return nil, err } return entry.Value, nil }