Skip to content

Commit

Permalink
Fix data race issue
Browse files Browse the repository at this point in the history
  • Loading branch information
webermarci committed Apr 7, 2024
1 parent 0403241 commit 82890bb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pantry.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ func New[T any](ctx context.Context, expiration time.Duration) *Pantry[T] {
for {
select {
case <-ticker.C:
pantry.mutex.Lock()
for key, item := range pantry.store {
if time.Now().UnixNano() > item.Expires {
pantry.Remove(key)
delete(pantry.store, key)
}
}
pantry.mutex.Unlock()

case <-ctx.Done():
pantry.mutex.Lock()
Expand Down

0 comments on commit 82890bb

Please sign in to comment.