Merge pull request #7 from DrTall/patch-1

Add threadsafety notes
This commit is contained in:
Jaime Pillora 2016-04-07 12:52:02 +10:00
commit 8dc7c27404
1 changed files with 7 additions and 0 deletions

View File

@ -10,6 +10,10 @@ import (
//After every call to Duration() it is multiplied by Factor. //After every call to Duration() it is multiplied by Factor.
//It is capped at Max. It returns to Min on every call to Reset(). //It is capped at Max. It returns to Min on every call to Reset().
//Used in conjunction with the time package. //Used in conjunction with the time package.
//
// Backoff is not threadsafe, but the ForAttempt method can be
// used concurrently if non-zero values for Factor, Max, and Min
// are set on the Backoff shared among threads.
type Backoff struct { type Backoff struct {
//Factor is the multiplying factor for each increment step //Factor is the multiplying factor for each increment step
attempts, Factor float64 attempts, Factor float64
@ -31,6 +35,9 @@ func (b *Backoff) Duration() time.Duration {
// you have a large number of independent Backoffs, but don't want use // you have a large number of independent Backoffs, but don't want use
// unnecessary memory storing the Backoff parameters per Backoff. The first // unnecessary memory storing the Backoff parameters per Backoff. The first
// attempt should be 0. // attempt should be 0.
//
// ForAttempt is threadsafe iff non-zero values for Factor, Max, and Min
// are set before any calls to ForAttempt are made.
func (b *Backoff) ForAttempt(attempt float64) time.Duration { func (b *Backoff) ForAttempt(attempt float64) time.Duration {
//Zero-values are nonsensical, so we use //Zero-values are nonsensical, so we use
//them to apply defaults //them to apply defaults