memory.EventStore¶
An in-memory implementation of EventStore. Suitable for testing and prototyping. Data is lost when the process exits.
Package¶
github.com/terraskye/eventsourcing/eventstore/memory
Constructor¶
func NewMemoryStore(buffer int64) *MemoryStore
| Parameter | Description |
|---|---|
buffer |
Size of the internal Events() channel buffer. |
store := memory.NewMemoryStore(100)
defer store.Close()
Events channel¶
func (m *MemoryStore) Events() <-chan *eventsourcing.Envelope
Returns a channel that receives every saved event. Use this to feed events into the event bus:
go func() {
for env := range store.Events() {
bus.Dispatch(env)
}
}()
Behaviour¶
- All events are stored in a
map[string][]*Envelope(per stream) and a global[]*Envelopeslice. LoadFromAlluses the global slice;versionis treated as a slice offset.LoadStreamrequires the stream to exist (StreamExistssemantics).LoadStreamFromwithAny{}orRevisionstarts from the given offset.- Thread-safe via
sync.RWMutex. Closeclears all stored events and closes theEvents()channel — do not use the store after callingClose.
Limitations¶
- No durability — data lost on process exit.
- No event registration required (events are not serialized).
LoadFromAllpositions are ordinal offsets, not global sequence numbers.