func Cancel(ctx context.Context) Option {
	return statelessOptionFunc(func(duration time.Duration) time.Duration {
		select {
		case <-ctx.Done():
			return Stop
		default:
		}
		return duration
	})
}
Cancel configures a backoff policy to stop if the given context is done.
package backoff
import (
	"context"
	"math/rand"
	"time"
)
type Option interface {
	apply(b Policy) Policy
}
type optionFunc func(Policy) Policy
func (f optionFunc) apply(p Policy) Policy {
	return f(p)
}
type statelessOptionFunc func(time.Duration) time.Duration
func (f statelessOptionFunc) apply(p Policy) Policy {
	return &statelessOption{
		delegate: p,
		f:        f,
	}
}
func MaxRetries(max int) Option {
	return optionFunc(func(p Policy) Policy {
		return &maxRetriesOption{
			delegate: p,
			maxTries: max,
			numTries: 0,
		}
	})
}
func MaxInterval(maxInterval time.Duration) Option {
	return statelessOptionFunc(func(duration time.Duration) time.Duration {
		if duration > maxInterval {
			return maxInterval
		}
		return duration
	})
}
func Timeout(timeout time.Time) Option {
	return statelessOptionFunc(func(duration time.Duration) time.Duration {
		if duration == Stop {
			return Stop
		}
		now := time.Now()
		if now.After(timeout) {
			return Stop
		}
		if now.Add(duration).After(timeout) {
			return timeout.Sub(now)
		}
		return duration
	})
}