syncutil

package
v0.2.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 1 Imported by: 0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL