forked from infinit/elle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Backoff.hh
42 lines (38 loc) · 973 Bytes
/
Backoff.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#include <elle/Duration.hh>
namespace elle
{
namespace reactor
{
/// An exponential backoff.
///
/// Sleep for a delay, doubling it every time until it reaches a maximum.
class Backoff
{
/*------.
| Types |
`------*/
public:
using Self = Backoff;
/*-------------.
| Construction |
`-------------*/
public:
/// Create an exponential backoff.
///
/// @param base The first back off delay.
/// @param max The maximum back off delay.
Backoff(Duration base = 1s, Duration max = 1min);
public:
/// Wait for the current delay and double it for next time.
void
backoff();
/// The number of time we backed off already.
ELLE_ATTRIBUTE_R(int, times_backed);
/// The first back off delay.
ELLE_ATTRIBUTE_R(Duration, base_backoff);
/// The maximum back off delay.
ELLE_ATTRIBUTE_R(Duration, max_backoff);
};
}
}