ferd/backoff — pull request #4 by jpuigm (2014-10-28 21:08:33+00:00)
Title: Added jitter based incremental backoff features

Basic usage:

```erlang
$ ./rebar get-deps compile --config rebar.test.config && erl -pa ebin -env ERL_LIBS deps
==> proper (get-deps)
==> backoff (get-deps)
==> proper (compile)
make: `include/compile_flags.hrl' is up to date.
==> backoff (compile)
Erlang/OTP 17 [erts-6.2] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Eshell V6.2 (abort with ^G)
1> Backoff = backoff:init(1, 10000, self(), put_it).
{backoff,1,10000,1,false,put_it,<0.32.0>}
2>
2> self().
<0.32.0>
3> flush().
ok
4> backoff:fire(Backoff).
#Ref<0.0.0.42>
5> flush().
Shell got {timeout,#Ref<0.0.0.42>,put_it}
ok
6> flush().
ok
7> backoff:fire(Backoff).
#Ref<0.0.0.57>
8> flush().
Shell got {timeout,#Ref<0.0.0.57>,put_it}
ok
9> backoff:fire(Backoff).
#Ref<0.0.0.68>
10> receive {timeout, _, put_it} -> received end.
received
```

I've added `jittle/1` that toggles the state of the backoff to use jitter-based increments (`rand_increment/1,2`)

```erlang
86> Backoff = backoff:init(1, 10000, self(), put_it).
{backoff,1,10000,1,false,put_it,<0.120.0>}
90> B = backoff:jitter(Backoff).
{backoff,1,10000,1,true,put_it,<0.120.0>}
112> {_, B2} = backoff:fail(B).
{3,{backoff,1,10000,3,true,put_it,<0.120.0>}}
113> {_, B3} = backoff:fail(B2).
{8,{backoff,1,10000,8,true,put_it,<0.120.0>}}
114> {_, B4} = backoff:fail(B3).
{12,{backoff,1,10000,12,true,put_it,<0.120.0>}}
115> {_, B5} = backoff:fail(B4).
{20,{backoff,1,10000,20,true,put_it,<0.120.0>}}
116> {_, B6} = backoff:fail(B5).
{50,{backoff,1,10000,50,true,put_it,<0.120.0>}}
117> {_, B7} = backoff:fail(B6).
{108,{backoff,1,10000,108,true,put_it,<0.120.0>}}
```