github.com/songzhibin97/gkit@v1.2.13/distributed/retry/fibonacci.go (about)

     1  package retry
     2  
     3  // Fibonacci returns successive Fibonacci numbers starting from 1
     4  func Fibonacci(max ...int) func() int {
     5  	max = append(max, 20)
     6  	a, b := 0, 1
     7  	return func() int {
     8  		if max[0] == 0 {
     9  			return a
    10  		}
    11  		max[0]--
    12  		a, b = b, a+b
    13  		return a
    14  	}
    15  }
    16  
    17  // FibonacciNext returns next number in Fibonacci sequence greater than start
    18  func FibonacciNext(start int) int {
    19  	fib := Fibonacci()
    20  	num := fib()
    21  	for num <= start {
    22  		num = fib()
    23  	}
    24  	return num
    25  }