Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager[T any] struct { // contains filtered or unexported fields }
Manager is a generic wrapper around a state object T which is serialized to the storage as JSON. It provides ways to safely mutate the state, backed by file locks.
func NewFromDisk ¶
NewFromDisk initializes a state manager with the state that is exists on disk, if nothing is found on the disk it uses the provided default.
func (*Manager[T]) Commit ¶
Commit acquires an exclusive lock, then atomically writes the current state to the file.
func (*Manager[T]) Load ¶
Load acquires a shared lock, then reads and decodes the state from the file.
func (*Manager[T]) ModifyState ¶
ModifyState acquires an exclusive lock, loads the current state. It then calls the callback function on the state to modify it before writing back to disk.
Click to show internal directories.
Click to hide internal directories.