Documentation
¶
Overview ¶
Package syncutil provides concurrency utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetOrCreate ¶
func GetOrCreate[K comparable, V any]( mu *sync.RWMutex, cache map[K]V, key K, create func() (V, error), ) (V, error)
GetOrCreate looks up key in cache under a read lock; if missing, acquires a write lock, double-checks, and calls create to populate the entry. The entry is stored in cache only when create returns a nil error. create is called while the write lock is held, so it is safe for create to read or write other fields protected by the same mu.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.