github.com/richardbowden/terraform@v0.6.12-0.20160901200758-30ea22c25211/builtin/providers/triton/utils.go (about)

     1  package triton
     2  
     3  import (
     4  	"errors"
     5  	"time"
     6  )
     7  
     8  var (
     9  	// ErrTimeout is returned when waiting for state change
    10  	ErrTimeout = errors.New("timed out while waiting for resource change")
    11  )
    12  
    13  func waitFor(f func() (bool, error), every, timeout time.Duration) error {
    14  	start := time.Now()
    15  
    16  	for time.Since(start) <= timeout {
    17  		stop, err := f()
    18  		if err != nil {
    19  			return err
    20  		}
    21  
    22  		if stop {
    23  			return nil
    24  		}
    25  
    26  		time.Sleep(every)
    27  	}
    28  
    29  	return ErrTimeout
    30  }