github.com/cyverse/go-irodsclient@v0.13.2/irods/util/timeout.go (about)

     1  package util
     2  
     3  import (
     4  	"sync"
     5  	"time"
     6  )
     7  
     8  // WaitTimeout waits for the waitgroup for the specified max timeout.
     9  // Returns true if waiting timed out.
    10  func WaitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool {
    11  	c := make(chan struct{})
    12  	go func() {
    13  		defer close(c)
    14  		wg.Wait()
    15  	}()
    16  
    17  	select {
    18  	case <-c:
    19  		return false // completed normally
    20  	case <-time.After(timeout):
    21  		return true // timed out
    22  	}
    23  }