persistence

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorPersistenceNotHasRecord = errors.New("persistence not has record")
)

Functions

This section is empty.

Types

type Event

type Event = any

Event 是的触发状态变更的事件

type FunctionalStateConfigurator

type FunctionalStateConfigurator func(configuration *StateConfiguration)

func (FunctionalStateConfigurator) Configure

func (f FunctionalStateConfigurator) Configure(configuration *StateConfiguration)

type FunctionalStorageProvider

type FunctionalStorageProvider func() Storage

func (FunctionalStorageProvider) Provide

func (f FunctionalStorageProvider) Provide() Storage

type MemoryStorage

type MemoryStorage struct{}

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

func (*MemoryStorage) Clear

func (m *MemoryStorage) Clear(name Name) error

func (*MemoryStorage) Load

func (m *MemoryStorage) Load(name Name) (snapshot Snapshot, events []Event, err error)

func (*MemoryStorage) Save

func (m *MemoryStorage) Save(name Name, snapshot Snapshot, events []Event) error

type Name

type Name = string

Name 持久化名称

type Snapshot

type Snapshot = any

Snapshot 持久化快照是完整的状态

type State

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

State 是持久化对象的运行时状态,其中包含的记录的事件及快照信息

func NewState

func NewState(name Name, configurator ...StateConfigurator) *State

func (*State) Clear

func (s *State) Clear() error

func (*State) EventCount

func (s *State) EventCount() int

func (*State) Load

func (s *State) Load() (snapshot Snapshot, events []Event, err error)

func (*State) Persist

func (s *State) Persist() error

func (*State) SaveSnapshot

func (s *State) SaveSnapshot(snapshot Snapshot)

func (*State) StateChanged

func (s *State) StateChanged(event Event) int

type StateConfiguration

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

func (*StateConfiguration) WithStorage

func (c *StateConfiguration) WithStorage(storage Storage) *StateConfiguration

type StateConfigurator

type StateConfigurator interface {
	Configure(configuration *StateConfiguration)
}

type Storage

type Storage interface {
	// Save 保存特定名称的状态快照及事件
	Save(name Name, snapshot Snapshot, events []Event) error

	// Load 加载特定名称的状态快照和事件
	Load(name Name) (snapshot Snapshot, events []Event, err error)

	// Clear 清除特定名称的状态快照和事件
	Clear(name Name) error
}

Storage 是用作 Actor 状态持久化的存储接口

type StorageProvider

type StorageProvider interface {
	Provide() Storage
}

Jump to

Keyboard shortcuts

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