snapshot of https://github.com/ThreeDotsLabs/watermill.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
master / ci (push) Failing after 0s
Some checks failed
master / ci (push) Failing after 0s
This commit is contained in:
23
pubsub/sync/waitgroup.go
Normal file
23
pubsub/sync/waitgroup.go
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user