mirror of https://github.com/jpillora/backoff.git
added some more docs
This commit is contained in:
parent
886d12305b
commit
d61cb21927
18
README.md
18
README.md
|
@ -12,11 +12,11 @@ $ go get -v github.com/jpillora/backoff
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
Backoff is a `time.Duration` counter. It starts at `Min`. After every call to `Duration()` it is multiplied by `Factor`. It is capped at `Max`. It returns to `Min` on every call to `Reset()`. Used in conjunction with the `time` package.
|
Backoff is a `time.Duration` counter. It starts at `Min`. After every call to `Duration()` it is multiplied by `Factor`. It is capped at `Max`. It returns to `Min` on every call to `Reset()`. `Jitter` adds randomness ([see below](#exampleusingjitter)). Used in conjunction with the `time` package.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Simple example**
|
#### Simple example
|
||||||
|
|
||||||
``` go
|
``` go
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ Reset!
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Example using `net` package**
|
#### Example using `net` package
|
||||||
|
|
||||||
``` go
|
``` go
|
||||||
b := &backoff.Backoff{
|
b := &backoff.Backoff{
|
||||||
|
@ -73,20 +73,16 @@ for {
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Exmaple using `Jitter`**
|
---
|
||||||
|
|
||||||
Setting `Jitter` adds some randomization to the backoff durations.
|
#### Example using `Jitter`
|
||||||
[See amazon's writeup of performance gains using jitter](http://www.awsarchitectureblog.com/2015/03/backoff.html).
|
|
||||||
Seeding is not necessary but doing so gives repeatable results.
|
Enabling `Jitter` adds some randomization to the backoff durations. [See Amazon's writeup of performance gains using jitter](http://www.awsarchitectureblog.com/2015/03/backoff.html). Seeding is not necessary but doing so gives repeatable results.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import "math/rand"
|
import "math/rand"
|
||||||
|
|
||||||
b := &backoff.Backoff{
|
b := &backoff.Backoff{
|
||||||
//These are the defaults
|
|
||||||
Min: 100 * time.Millisecond,
|
|
||||||
Max: 10 * time.Second,
|
|
||||||
Factor: 2,
|
|
||||||
Jitter: true,
|
Jitter: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue