Skip to content

Commit

Permalink
reorganizes methods to be grouped by type
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewpmartinez committed Mar 6, 2024
1 parent e4207d9 commit bc140c8
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions common/event_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit bc140c8

Please sign in to comment.