statemanager

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultStatePath

func GetDefaultStatePath() string

GetDefaultStatePath returns the path to the state file based on the operating system It returns an empty string if the path cannot be determined.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles the persistence and management of various states

func New

func New(filePath string) *Manager

New creates a new Manager instance

func (*Manager) DeleteState

func (m *Manager) DeleteState(state State) error

DeleteState removes the state from the manager and marks it as dirty for the next save. Pass an uninitialized state to delete it.

func (*Manager) GetState

func (m *Manager) GetState(state State) State

GetState returns the state for the given type

func (*Manager) PerformCleanup

func (m *Manager) PerformCleanup() error

PerformCleanup retrieves all states from the state file for the registered states and calls Cleanup on them. If the cleanup is successful, the state is marked for deletion.

func (*Manager) PersistState

func (m *Manager) PersistState(ctx context.Context) error

PersistState persists the states that have been updated since the last save.

func (*Manager) RegisterState

func (m *Manager) RegisterState(state State)

RegisterState registers a state with the manager but doesn't attempt to persist it. Pass an uninitialized state to register it.

func (*Manager) Start

func (m *Manager) Start()

Start starts the state manager periodic save routine

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context) error

func (*Manager) UpdateState

func (m *Manager) UpdateState(state State) error

UpdateState updates the state in the manager and marks it as dirty for the next save. The state will be replaced with the new one.

type State

type State interface {
	Name() string
	Cleanup() error
}

State interface defines the methods that all state types must implement

Jump to

Keyboard shortcuts

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