storage

package
v0.2.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Initer

type Initer interface {
	Init()
}

Initer is optionally implemented by T to initialize zero-value fields (e.g., nil maps) after deserialization or when the backing store is empty.

type Store

type Store[T any] interface {
	// With loads the data under lock and passes it to fn.
	// If *T implements Initer, Init() is called before fn.
	// The lock is held for the duration of fn.
	With(ctx context.Context, fn func(*T) error) error
	// Update performs a read-modify-write under lock.
	// If fn returns nil the data is persisted.
	Update(ctx context.Context, fn func(*T) error) error

	// ReadRaw deserializes the data and passes it to fn without acquiring the lock.
	// The caller must already hold the lock via TryLock.
	ReadRaw(fn func(*T) error) error
	// WriteRaw deserializes the data, passes it to fn, and atomically persists the
	// result if fn returns nil. Does not acquire the lock.
	// The caller must already hold the lock via TryLock.
	WriteRaw(fn func(*T) error) error
	// TryLock attempts to acquire the lock without blocking.
	// Returns (false, nil) if currently held by another caller.
	// On success (true, nil) the caller must call Unlock when done.
	TryLock(ctx context.Context) (bool, error)
	// Unlock releases a lock previously acquired by TryLock.
	Unlock(ctx context.Context) error
}

Store provides locked read/modify/write access to a data store. T is the top-level structure managed by the store.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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