File: backoff.go

package info (click to toggle)
golang-github-lestrrat-go-backoff 2.0.8-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 200 kB
  • sloc: makefile: 2
file content (31 lines) | stat: -rw-r--r-- 677 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package backoff

// Null creates a new NullPolicy object
func Null() Policy {
	return NewNull()
}

// Constant creates a new ConstantPolicy object
func Constant(options ...Option) Policy {
	return NewConstantPolicy(options...)
}

// Constant creates a new ExponentialPolicy object
func Exponential(options ...ExponentialOption) Policy {
	return NewExponentialPolicy(options...)
}

// Continue is a convenience function to check when we can fire
// the next invocation of the desired backoff code
//
// for backoff.Continue(c) {
//  ... your code ...
// }
func Continue(c Controller) bool {
	select {
	case <-c.Done():
		return false
	case _, ok := <-c.Next():
		return ok
	}
}