backoff.go 677 B

12345678910111213141516171819202122232425262728293031
  1. package backoff
  2. // Null creates a new NullPolicy object
  3. func Null() Policy {
  4. return NewNull()
  5. }
  6. // Constant creates a new ConstantPolicy object
  7. func Constant(options ...Option) Policy {
  8. return NewConstantPolicy(options...)
  9. }
  10. // Constant creates a new ExponentialPolicy object
  11. func Exponential(options ...ExponentialOption) Policy {
  12. return NewExponentialPolicy(options...)
  13. }
  14. // Continue is a convenience function to check when we can fire
  15. // the next invocation of the desired backoff code
  16. //
  17. // for backoff.Continue(c) {
  18. // ... your code ...
  19. // }
  20. func Continue(c Controller) bool {
  21. select {
  22. case <-c.Done():
  23. return false
  24. case _, ok := <-c.Next():
  25. return ok
  26. }
  27. }