Documentation ¶
Index ¶
- func AwaitSignal(ctx context.Context, signals ...os.Signal) error
- func Close(value any) error
- func Nop()
- func ReentrantLock(ctx context.Context, key any, requiredLevel uint, lock LockerFunc) (context.Context, context.CancelFunc)
- func Validate(value any) error
- type Clock
- type ClockFunc
- type FuncRef
- type Goroutine
- type Locker
- type LockerFunc
- type Lockers
- type RWMutex
- type Ref
- type Unit
- type WriteThroughCache
- type WriteThroughCacheStorage
- type WriteThroughCacheStorageFunc
- type WriteThroughCached
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AwaitSignal ¶
AwaitSignal waits for specified signals.
func ReentrantLock ¶
func ReentrantLock(ctx context.Context, key any, requiredLevel uint, lock LockerFunc) (context.Context, context.CancelFunc)
ReentrantLock will check context to see if the lock with required level or higher is already acquired. If not, it will call provided LockerFunc.
Types ¶
type Goroutine ¶
type Goroutine interface { // Cancel signals cancellation to the goroutine. Cancel() // Join waits for goroutine to finish. Join(ctx context.Context) error }
Goroutine describes goroutine handle.
type Locker ¶
type Locker interface { // Lock acquires the lock. // It returns a new Context which should be checked for error before proceeding with the execution. // Context scope must be limited to holding the lock. // CancelFunc must not be nil and is used in defer statement to release the lock or perform other cleanup, // even in cases of context errors. // // Example usage: // ctx, cancel := mu.Lock(ctx) // defer cancel() // if err := ctx.Err(); err != nil { // return err // } Lock(ctx context.Context) (context.Context, context.CancelFunc) }
Locker provides synchronization semantics similar to mutex. Implementations must provide interruptibility and reentrant locking.
type LockerFunc ¶
LockerFunc is a functional Locker adapter.
var Unlocker LockerFunc = func(ctx context.Context) (context.Context, context.CancelFunc) { return ctx, Nop }
Unlocker does nothing.
func (LockerFunc) Lock ¶
func (fn LockerFunc) Lock(ctx context.Context) (context.Context, context.CancelFunc)
type Lockers ¶
type Lockers []Locker
Lockers provides a way to simultaneously acquire and release multiple locks.
type RWMutex ¶
type RWMutex struct {
// contains filtered or unexported fields
}
RWMutex is a sync.RWMutex implementation.
type Ref ¶
Ref references a value which may require calculation.
func FutureFuncRef ¶ added in v1.0.0
func FutureRef ¶ added in v1.0.0
FutureRef represents a result of an asynchronous computation that may or may not be available yet.
func LazyFuncRef ¶ added in v1.0.0
func LazyRef ¶ added in v1.0.0
LazyRef creates a Ref with on-demand execution of the provided Ref. The result of the first execution will be cached and returned immediately for all consequent calls.
func SafeFuncRef ¶ added in v1.0.0
type WriteThroughCache ¶
type WriteThroughCache[K comparable, V comparable] struct { // contains filtered or unexported fields }
WriteThroughCache provides a simple write-through cache implementation.
func NewWriteThroughCache ¶
func NewWriteThroughCache[K comparable, V comparable](storage WriteThroughCacheStorage[K, V]) *WriteThroughCache[K, V]
NewWriteThroughCache creates a WriteThroughCache instance.
func (*WriteThroughCache[K, V]) Get ¶
func (c *WriteThroughCache[K, V]) Get(ctx context.Context, key K) (V, error)
Get attempts to retrieve the value from cache. If no cached value is present, it will be retrieved from underlying storage. If the value retrieved from storage is not zero, it will be cached.
type WriteThroughCacheStorage ¶
type WriteThroughCacheStorage[K comparable, V comparable] interface { // Load loads the value from storage. Load(ctx context.Context, key K) (V, error) // Update persists the value in storage. Update(ctx context.Context, key K, value V) error }
WriteThroughCacheStorage defines an interface for the underlying storage of WriteThroughCache.
type WriteThroughCacheStorageFunc ¶
type WriteThroughCacheStorageFunc[K comparable, V comparable] struct { LoadFn func(ctx context.Context, key K) (V, error) UpdateFn func(ctx context.Context, key K, value V) error }
WriteThroughCacheStorageFunc provides a functional adapter for WriteThroughCacheStorage.
type WriteThroughCached ¶
type WriteThroughCached[V comparable] struct { // contains filtered or unexported fields }
WriteThroughCached provides write-through cache semantics for a single value.
func NewWriteThroughCached ¶
func NewWriteThroughCached[K comparable, V comparable](storage WriteThroughCacheStorage[K, V], key K) *WriteThroughCached[V]
NewWriteThroughCached creates a WriteThroughCached instance.