Skip to content
/ backoff Public

(Library) Generic backoff policy.

Notifications You must be signed in to change notification settings

vidsy/backoff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

backoff

Go package for implementing a generic backoff policy.

Usage

package main

import (
  "log"

  "github/vidsy/backoff"
)

func main() {
  bp := backoff.Policy{
    Intervals: []int{0, 500, 1000, 2000, 4000, 8000},
    LogMessageHandler: func(message string) {
      log.Printf("Log message from backoff.Policy: %s", message)
    }
  }

  anon := func() (bool, error) {
    attemptConnection()
  }

  ok, err := bp.Perform(anon)
  if err != nil {
    log.Fatalf("Error in anon function: %s", err)
  }

  if !ok {
    log.Fatal("Failed to connect...")
  }

  log.Println("Success!")
}

func attemptConnection() bool {
  // Do something here...
  return false
}

Tests

$ go test -v

Notes

MIT License (MIT)

About

(Library) Generic backoff policy.

Resources

Stars

Watchers

Forks

Packages

No packages published