Skip to content

Commit

Permalink
Merge pull request #12 from statsig-io/remove-tail-recursion
Browse files Browse the repository at this point in the history
remove tail recursion
  • Loading branch information
jkw-statsig authored Apr 29, 2022
2 parents 35d1627 + 72995f9 commit 5cca123
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type store struct {
configSyncInterval time.Duration
idListSyncInterval time.Duration
shutdown bool
shutdownLock sync.Mutex
}

func newStore(transport *transport) *store {
Expand Down Expand Up @@ -257,23 +258,37 @@ func (s *store) syncIDLists() {
}

func (s *store) pollForIDListChanges() {
time.Sleep(s.idListSyncInterval)
if s.shutdown {
return
for {
time.Sleep(s.idListSyncInterval)
stop := func() bool {
s.shutdownLock.Lock()
defer s.shutdownLock.Unlock()
return s.shutdown
}()
if stop {
break
}
s.syncIDLists()
}
s.syncIDLists()
s.pollForIDListChanges()
}

func (s *store) pollForRulesetChanges() {
time.Sleep(s.configSyncInterval)
if s.shutdown {
return
for {
time.Sleep(s.configSyncInterval)
stop := func() bool {
s.shutdownLock.Lock()
defer s.shutdownLock.Unlock()
return s.shutdown
}()
if stop {
break
}
s.fetchConfigSpecs()
}
s.fetchConfigSpecs()
s.pollForRulesetChanges()
}

func (s *store) stopPolling() {
s.shutdownLock.Lock()
defer s.shutdownLock.Unlock()
s.shutdown = true
}

0 comments on commit 5cca123

Please sign in to comment.