Skip to content

Commit

Permalink
Upgrade panic safety comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mgnsk committed May 21, 2023
1 parent 3b90b8a commit 5a2bd95
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c *Cache[K, V]) LoadOrStore(key K, ttl time.Duration, value V) (old V, loa
return v, loaded
}

// MustFetch fetches a value without handling errors. It is safe to panic in f.
// MustFetch fetches a value or panics if f panics.
func (c *Cache[K, V]) MustFetch(key K, ttl time.Duration, f func() V) (value V) {
v, _ := c.TryFetch(key, func() (V, time.Duration, error) {
value := f()
Expand All @@ -96,7 +96,7 @@ func (c *Cache[K, V]) MustFetch(key K, ttl time.Duration, f func() V) (value V)
}

// Fetch loads or stores a value for key. If a value exists, f will not be called,
// otherwise f will be called to fetch the new value. It is safe to panic in f.
// otherwise f will be called to fetch the new value. It panics if f panics.
// Concurrent Fetches for the same key will block each other and return a single result.
func (c *Cache[K, V]) Fetch(key K, ttl time.Duration, f func() (V, error)) (value V, err error) {
return c.TryFetch(key, func() (V, time.Duration, error) {
Expand Down

0 comments on commit 5a2bd95

Please sign in to comment.