Skip to content

abelcervantes/backoff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⏱️ ️backoff ⏱️

Go Build Status codecov

A simple truncated backoff algorithm implementation made with go!

Installation

go get github.com/abelcervantes/backoff

Formula

To calculate the next duration: ((2^attempts) - 1) * slotTime

Usage

default:

package main

import (
	"time"

	"github.com/abelcervantes/backoff"
)

func main() {
    b := backoff.NewDefault()
    time.Sleep(b.NextDuration())
}

custom:

package main

import (
	"time"

	"github.com/abelcervantes/backoff"
)

func main() {
    b, err := backoff.New(2*time.Second, 20*time.Second, 400*time.Millisecond, false, 10)
    if err != nil {
        log.Fatal(err)
    }	
    time.Sleep(b.NextDuration())
}

References

About

A simple truncated backoff algorithm implementation in Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages