snapshot of https://github.com/ThreeDotsLabs/watermill.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
master / ci (push) Failing after 0s

This commit is contained in:
upstream-mirror
2026-09-15 21:27:46 +05:00
commit ce933d1277
538 changed files with 46504 additions and 0 deletions

23
pubsub/sync/waitgroup.go Normal file
View File

@@ -0,0 +1,23 @@
package sync
import (
"sync"
"time"
)
// WaitGroupTimeout adds timeout feature for sync.WaitGroup.Wait().
// It returns true, when timed out.
func WaitGroupTimeout(wg *sync.WaitGroup, timeout time.Duration) bool {
wgClosed := make(chan struct{}, 1)
go func() {
wg.Wait()
wgClosed <- struct{}{}
}()
select {
case <-wgClosed:
return false
case <-time.After(timeout):
return true
}
}

View File

@@ -0,0 +1,24 @@
package sync
import (
"sync"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestWaitGroupTimeout_no_timeout(t *testing.T) {
wg := &sync.WaitGroup{}
timedout := WaitGroupTimeout(wg, time.Millisecond*100)
assert.False(t, timedout)
}
func TestWaitGroupTimeout_timeout(t *testing.T) {
wg := &sync.WaitGroup{}
wg.Add(1)
timedout := WaitGroupTimeout(wg, time.Millisecond*100)
assert.True(t, timedout)
}