diff --git a/concurrenz/atomic_value.go b/concurrenz/atomic_value.go index 312b0e5..206030f 100644 --- a/concurrenz/atomic_value.go +++ b/concurrenz/atomic_value.go @@ -29,5 +29,10 @@ func (self *AtomicValue[T]) Load() T { if val := (*atomic.Value)(self).Load(); val != nil { result = val.(T) } + return result } + +func (self *AtomicValue[T]) CompareAndSwap(old, new T) bool { + return (*atomic.Value)(self).CompareAndSwap(old, new) +} diff --git a/concurrenz/atomic_value_test.go b/concurrenz/atomic_value_test.go new file mode 100644 index 0000000..d2d7fa3 --- /dev/null +++ b/concurrenz/atomic_value_test.go @@ -0,0 +1,21 @@ +package concurrenz + +import ( + "github.com/stretchr/testify/require" + "testing" +) + +func TestAtomicValue_CompareAndSwap(t *testing.T) { + v := &AtomicValue[string]{} + + req := require.New(t) + req.Equal("", v.Load()) + v.Store("hello") + req.Equal("hello", v.Load()) + req.Equal(false, v.CompareAndSwap("world", "foo")) + req.Equal("hello", v.Load()) + req.Equal(true, v.CompareAndSwap("hello", "world")) + req.Equal("world", v.Load()) + v.Store("foo") + req.Equal("foo", v.Load()) +} diff --git a/concurrenz/wait_group.go b/concurrenz/wait_group.go index a4d8a55..021f7f9 100644 --- a/concurrenz/wait_group.go +++ b/concurrenz/wait_group.go @@ -23,8 +23,9 @@ import ( ) // WaitGroup provides a facility to wait for an arbitrarily size collection of notification channels to be completed -// The methods are multi-thread safe, but notifiers added after WaitForDone has been called are not guaranteed -// to be waited for +// +// The methods are multi-thread safe, but notifiers added after WaitForDone has been called are not guaranteed +// to be waited for type WaitGroup interface { // AddNotifier adds a notifier to the wait group AddNotifier(ch <-chan struct{}) diff --git a/info/time.go b/info/time.go index 0566db0..96c78ac 100644 --- a/info/time.go +++ b/info/time.go @@ -19,7 +19,6 @@ package info import "time" // Return the current time in milliseconds. -// func NowInMilliseconds() int64 { return time.Now().UnixNano() / 1000000 } diff --git a/term/prompt.go b/term/prompt.go index 5cb48bd..56de5c5 100644 --- a/term/prompt.go +++ b/term/prompt.go @@ -52,7 +52,8 @@ func PromptPassword(prompt string, allowEmpty bool) (string, error) { } // Prompt will output the given prompt and return the line entered by the user. -// The line will be trimmed of white-space. +// +// The line will be trimmed of white-space. func Prompt(prompt string) (string, error) { fmt.Print(prompt) diff --git a/tlz/cipher.go b/tlz/cipher.go index 662e485..f3e4000 100644 --- a/tlz/cipher.go +++ b/tlz/cipher.go @@ -52,7 +52,7 @@ func GetMinTlsVersion() uint16 { return tls.VersionTLS12 } -//Note: This will only affect TLS1.2 and lower, TLS1.3 has a separate smaller cipher set managed by Go. +// Note: This will only affect TLS1.2 and lower, TLS1.3 has a separate smaller cipher set managed by Go. func GetCipherSuites() []uint16 { once.Do(setDefaultCipherSuites) return defaultCipherSuites