Created
December 16, 2021 17:50
-
-
Save dragonsinth/5bef35eb998d22f1fbf2af63ae1338bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type LogReplicatedModel struct { | |
mu sync.RWMutex | |
snapshot Model | |
stream eventstream.EventStream | |
} | |
func (m *LogReplicatedModel) ReadAndSubscribe() (Model, eventstream.Promise) { | |
m.mu.RLock() | |
defer m.mu.RUnlock() | |
return m.snapshot, m.stream.Subscribe() | |
} | |
func (m *LogReplicatedModel) WriteAndPublish(mutation Mutation) { | |
m.mu.Lock() | |
defer m.mu.Unlock() | |
m.snapshot = m.snapshot.ApplyMutation(mutation) | |
m.stream.Publish(mutation) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment