github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/state/state.go (about) 1 package state 2 3 import "sync/atomic" 4 5 // State is a thread safe FunctionState struct 6 type State struct { 7 fs int32 8 } 9 10 // Set the state in a thread safe way 11 func (s *State) Set(fs FunctionState) { 12 atomic.StoreInt32(&s.fs, int32(fs)) 13 } 14 15 // Get the state in a thread safe way 16 func (s *State) Get() FunctionState { 17 fs := atomic.LoadInt32(&s.fs) 18 return FunctionState(fs) 19 } 20 21 // String is a stringer function for Get() 22 func (s *State) String() string { 23 fs := atomic.LoadInt32(&s.fs) 24 return FunctionState(fs).String() 25 }