1
0
forked from extern/smegmesh
smegmesh/pkg/mesh/monitor.go

29 lines
544 B
Go
Raw Normal View History

package mesh
type OnChange = func(string, MeshSnapshot)
type MeshMonitor interface {
AddCallback(cb OnChange)
Trigger(meshid string, m MeshSnapshot)
}
type MeshMonitorImpl struct {
callbacks []OnChange
}
func (m *MeshMonitorImpl) Trigger(meshid string, snapshot MeshSnapshot) {
for _, cb := range m.callbacks {
cb(meshid, snapshot)
}
}
func (m *MeshMonitorImpl) AddCallback(cb OnChange) {
m.callbacks = append(m.callbacks, cb)
}
func NewMeshMonitor() MeshMonitor {
return &MeshMonitorImpl{
callbacks: make([]OnChange, 0),
}
}