reorganizes methods to be grouped by type

This commit is contained in:
Andrew Martinez
2024-03-06 10:04:58 -05:00
parent e4207d9f9f
commit bc140c87df
+16 -16
View File
@@ -88,22 +88,6 @@ func (cache *ForgetfulEventCache) ReplayFrom(_ uint64) ([]*edge_ctrl_pb.DataStat
return nil, false
}
func NewLoggingEventCache(logSize uint64) *LoggingEventCache {
return &LoggingEventCache{
HeadLogIndex: 0,
LogSize: logSize,
Log: make([]uint64, logSize),
Events: map[uint64]*edge_ctrl_pb.DataState_Event{},
}
}
func (cache *LoggingEventCache) WhileLocked(callback func(uint64, bool)) {
cache.lock.Lock()
defer cache.lock.Unlock()
callback(cache.currentIndex())
}
func (cache *ForgetfulEventCache) CurrentIndex() (uint64, bool) {
cache.lock.Lock()
defer cache.lock.Unlock()
@@ -128,6 +112,15 @@ type LoggingEventCache struct {
Events map[uint64]*edge_ctrl_pb.DataState_Event
}
func NewLoggingEventCache(logSize uint64) *LoggingEventCache {
return &LoggingEventCache{
HeadLogIndex: 0,
LogSize: logSize,
Log: make([]uint64, logSize),
Events: map[uint64]*edge_ctrl_pb.DataState_Event{},
}
}
func (cache *LoggingEventCache) SetCurrentIndex(index uint64) {
cache.lock.Lock()
defer cache.lock.Unlock()
@@ -138,6 +131,13 @@ func (cache *LoggingEventCache) SetCurrentIndex(index uint64) {
cache.Events = map[uint64]*edge_ctrl_pb.DataState_Event{}
}
func (cache *LoggingEventCache) WhileLocked(callback func(uint64, bool)) {
cache.lock.Lock()
defer cache.lock.Unlock()
callback(cache.currentIndex())
}
func (cache *LoggingEventCache) Store(event *edge_ctrl_pb.DataState_Event, onSuccess OnStoreSuccess) error {
cache.lock.Lock()
defer cache.lock.Unlock()