From b6c53fd1f696eb5d8f32b8366a7bf154342b73fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 21 Aug 2026 12:24:41 +0200 Subject: [PATCH] all: Run modernize -fix ./... --- debounce_test.go | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/debounce_test.go b/debounce_test.go index ec73c5e..8b48c9a 100644 --- a/debounce_test.go +++ b/debounce_test.go @@ -17,20 +17,20 @@ import ( func TestDebounce(t *testing.T) { synctest.Test(t, func(t *testing.T) { var ( - counter1 uint64 - counter2 uint64 + counter1 atomic.Uint64 + counter2 atomic.Uint64 ) f1 := func() { - atomic.AddUint64(&counter1, 1) + counter1.Add(1) } f2 := func() { - atomic.AddUint64(&counter2, 1) + counter2.Add(1) } f3 := func() { - atomic.AddUint64(&counter2, 2) + counter2.Add(2) } debounced := debounce.New(100 * time.Millisecond) @@ -54,8 +54,8 @@ func TestDebounce(t *testing.T) { time.Sleep(200 * time.Millisecond) } - c1 := int(atomic.LoadUint64(&counter1)) - c2 := int(atomic.LoadUint64(&counter2)) + c1 := int(counter1.Load()) + c2 := int(counter2.Load()) if c1 != 3 { t.Error("Expected count 3, was", c1) } @@ -69,21 +69,21 @@ func TestDebounceConcurrentAdd(t *testing.T) { synctest.Test(t, func(t *testing.T) { var wg sync.WaitGroup - var flag uint64 + var flag atomic.Uint64 debounced := debounce.New(100 * time.Millisecond) for range 10 { wg.Go(func() { debounced(func() { - atomic.CompareAndSwapUint64(&flag, 0, 1) + flag.CompareAndSwap(0, 1) }) }) } wg.Wait() time.Sleep(500 * time.Millisecond) - c := int(atomic.LoadUint64(&flag)) + c := int(flag.Load()) if c != 1 { t.Error("Flag not set") } @@ -94,11 +94,11 @@ func TestDebounceConcurrentAdd(t *testing.T) { func TestDebounceDelayed(t *testing.T) { synctest.Test(t, func(t *testing.T) { var ( - counter1 uint64 + counter1 atomic.Uint64 ) f1 := func() { - atomic.AddUint64(&counter1, 1) + counter1.Add(1) } debounced := debounce.New(100 * time.Millisecond) @@ -109,7 +109,7 @@ func TestDebounceDelayed(t *testing.T) { time.Sleep(200 * time.Millisecond) - c1 := int(atomic.LoadUint64(&counter1)) + c1 := int(counter1.Load()) if c1 != 1 { t.Error("Expected count 1, was", c1) } @@ -117,10 +117,10 @@ func TestDebounceDelayed(t *testing.T) { } func BenchmarkDebounce(b *testing.B) { - var counter uint64 + var counter atomic.Uint64 f := func() { - atomic.AddUint64(&counter, 1) + counter.Add(1) } debounced := debounce.New(100 * time.Millisecond) @@ -130,17 +130,17 @@ func BenchmarkDebounce(b *testing.B) { debounced(f) } - c := int(atomic.LoadUint64(&counter)) + c := int(counter.Load()) if c != 0 { b.Fatal("Expected count 0, was", c) } } func ExampleNew() { - var counter uint64 + var counter atomic.Uint64 f := func() { - atomic.AddUint64(&counter, 1) + counter.Add(1) } debounced := debounce.New(100 * time.Millisecond) @@ -153,7 +153,7 @@ func ExampleNew() { time.Sleep(200 * time.Millisecond) } - c := int(atomic.LoadUint64(&counter)) + c := int(counter.Load()) fmt.Println("Counter is", c) // Output: Counter is 3 @@ -161,13 +161,13 @@ func ExampleNew() { func TestDebounceCancel(t *testing.T) { synctest.Test(t, func(t *testing.T) { - var called int32 + var called atomic.Int32 debounced, cancel := debounce.NewWithCancel(50 * time.Millisecond) // Schedule a call that would normally be executed. debounced(func() { - atomic.StoreInt32(&called, 1) + called.Store(1) }) // Cancel it before the timer is triggered. @@ -177,7 +177,7 @@ func TestDebounceCancel(t *testing.T) { //the function will execute and the test will fail. time.Sleep(70 * time.Millisecond) - if atomic.LoadInt32(&called) != 0 { + if called.Load() != 0 { t.Fatal("expected debounced function NOT to be called after cancel") }