You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/index.md
+18-29Lines changed: 18 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,13 +15,13 @@ Configure base time, cap time, strategy and jitter. All options are required:
15
15
16
16
use Orangesoft\BackOff\Generator\Generator;
17
17
use Orangesoft\BackOff\Duration\DurationInterface;
18
-
use Orangesoft\BackOff\Duration\Milliseconds;
18
+
use Orangesoft\BackOff\Duration\Seconds;
19
19
use Orangesoft\BackOff\Strategy\ExponentialStrategy;
20
20
use Orangesoft\BackOff\Jitter\NullJitter;
21
21
22
22
$generator = new Generator(
23
-
baseTime: new Milliseconds(1_000),
24
-
capTime: new Milliseconds(60_000),
23
+
baseTime: new Seconds(1),
24
+
capTime: new Seconds(60),
25
25
strategy: new ExponentialStrategy(multiplier: 2),
26
26
jitter: new NullJitter(),
27
27
);
@@ -48,13 +48,13 @@ Enabled Jitter allows to add a noise for the back-off time. Turn on it is very s
48
48
49
49
use Orangesoft\BackOff\Generator\Generator;
50
50
use Orangesoft\BackOff\Duration\DurationInterface;
51
-
use Orangesoft\BackOff\Duration\Milliseconds;
51
+
use Orangesoft\BackOff\Duration\Seconds;
52
52
use Orangesoft\BackOff\Strategy\ExponentialStrategy;
53
53
use Orangesoft\BackOff\Jitter\EqualJitter;
54
54
55
55
$generator = new Generator(
56
-
baseTime: new Milliseconds(1_000),
57
-
capTime: new Milliseconds(60_000),
56
+
baseTime: new Seconds(1),
57
+
capTime: new Seconds(60),
58
58
strategy: new ExponentialStrategy(multiplier: 2),
59
59
jitter: new EqualJitter(),
60
60
);
@@ -71,14 +71,14 @@ Pass the duration time to Sleeper as below:
71
71
72
72
use Orangesoft\BackOff\Generator\Generator;
73
73
use Orangesoft\BackOff\Duration\DurationInterface;
74
-
use Orangesoft\BackOff\Duration\Milliseconds;
74
+
use Orangesoft\BackOff\Duration\Seconds;
75
75
use Orangesoft\BackOff\Strategy\ExponentialStrategy;
76
76
use Orangesoft\BackOff\Jitter\NullJitter;
77
77
use Orangesoft\BackOff\Sleeper\Sleeper;
78
78
79
79
$generator = new Generator(
80
-
baseTime: new Milliseconds(1_000),
81
-
capTime: new Milliseconds(60_000),
80
+
baseTime: new Seconds(1),
81
+
capTime: new Seconds(60),
82
82
strategy: new ExponentialStrategy(multiplier: 2),
83
83
jitter: new NullJitter(),
84
84
);
@@ -88,21 +88,10 @@ $sleeper = new Sleeper();
88
88
/** @var DurationInterface $duration */
89
89
$duration = $generator->generate(attempt: 3);
90
90
91
-
// usleep(8000000)
91
+
// time_nanosleep(8, 0)
92
92
$sleeper->sleep($duration);
93
93
```
94
94
95
-
Configure base time and cap time with microseconds precision because Sleeper converts the duration to integer before sleep and truncates numbers after point. For example 1 nanosecond is 0.001 microseconds, so it would to converted to 0:
96
-
97
-
```text
98
-
+--------------+-------------+
99
-
| Nanoseconds | 1 |
100
-
| Microseconds | 0.001 |
101
-
| Milliseconds | 0.000001 |
102
-
| Seconds | 0.000000001 |
103
-
+--------------+-------------+
104
-
```
105
-
106
95
Use nanoseconds for high-precision calculations.
107
96
108
97
## Use BackOff
@@ -114,15 +103,15 @@ BackOff accepts Generator and Sleeper dependencies:
114
103
115
104
use Orangesoft\BackOff\Generator\Generator;
116
105
use Orangesoft\BackOff\Duration\DurationInterface;
117
-
use Orangesoft\BackOff\Duration\Milliseconds;
106
+
use Orangesoft\BackOff\Duration\Seconds;
118
107
use Orangesoft\BackOff\Strategy\ExponentialStrategy;
119
108
use Orangesoft\BackOff\Jitter\NullJitter;
120
109
use Orangesoft\BackOff\Sleeper\Sleeper;
121
110
use Orangesoft\BackOff\BackOff;
122
111
123
112
$generator = new Generator(
124
-
baseTime: new Milliseconds(1_000),
125
-
capTime: new Milliseconds(60_000),
113
+
baseTime: new Seconds(1),
114
+
capTime: new Seconds(60),
126
115
strategy: new ExponentialStrategy(multiplier: 2),
127
116
jitter: new NullJitter(),
128
117
);
@@ -146,14 +135,14 @@ Use back-off decorators to quick instance. For example [ExponentialBackOff](../s
146
135
<?php
147
136
148
137
use Orangesoft\BackOff\ExponentialBackOff;
149
-
use Orangesoft\BackOff\Duration\Milliseconds;
138
+
use Orangesoft\BackOff\Duration\Seconds;
150
139
use Orangesoft\BackOff\Jitter\NullJitter;
151
140
use Orangesoft\BackOff\Sleeper\Sleeper;
152
141
153
142
$backOff = new ExponentialBackOff(
154
143
maxAttempts: 3,
155
-
baseTime: new Milliseconds(1_000),
156
-
capTime: new Milliseconds(60_000),
144
+
baseTime: new Seconds(1),
145
+
capTime: new Seconds(60),
157
146
multiplier: 2,
158
147
jitter: new NullJitter(),
159
148
sleeper: new Sleeper(),
@@ -176,13 +165,13 @@ Configure BackOff and ExceptionClassifier to retry your business logic when an e
176
165
<?php
177
166
178
167
use Orangesoft\BackOff\ExponentialBackOff;
179
-
use Orangesoft\BackOff\Duration\Milliseconds;
168
+
use Orangesoft\BackOff\Duration\Seconds;
180
169
use Orangesoft\BackOff\Retry\ExceptionClassifier\ExceptionClassifier;
0 commit comments