From 5a2bd95eb69a99c2b0ca8f1e0bb4686ae298e091 Mon Sep 17 00:00:00 2001 From: Magnus Kokk Date: Sun, 21 May 2023 23:27:00 +0300 Subject: [PATCH] Upgrade panic safety comments --- cache.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cache.go b/cache.go index deae7a1..65ed4a8 100644 --- a/cache.go +++ b/cache.go @@ -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() @@ -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) {