func NonRetryableError(err error) *RetryError {
	if err == nil {
		return nil
	}
	return &RetryError{Err: err, Retryable: false}
}
NonRetryableError is a helper to create a RetryError that's _not)_ retryable
from a given error.
package resource
import (
	"sync"
	"time"
)
func Retry(timeout time.Duration, f RetryFunc) error {
	var resultErr error
	var resultErrMu sync.Mutex
	c := &StateChangeConf{
		Pending:    []string{"retryableerror"},
		Target:     []string{"success"},
		Timeout:    timeout,
		MinTimeout: 500 * time.Millisecond,
		Refresh: func() (interface{}, string, error) {
			rerr := f()
			resultErrMu.Lock()
			defer resultErrMu.Unlock()
			if rerr == nil {
				resultErr = nil
				return 42, "success", nil
			}
			resultErr = rerr.Err
			if rerr.Retryable {
				return 42, "retryableerror", nil
			}
			return nil, "quit", rerr.Err
		},
	}
	_, waitErr := c.WaitForState()
	resultErrMu.Lock()
	defer resultErrMu.Unlock()
	if resultErr == nil {
		return waitErr
	}
	return resultErr
}
type RetryFunc func() *RetryError
type RetryError struct {
	Err       error
	Retryable bool
}
func RetryableError(err error) *RetryError {
	if err == nil {
		return nil
	}
	return &RetryError{Err: err, Retryable: true}
}