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
@@ -96,21 +96,21 @@ The retry algorithm follows this sequence:
96
96
1. Execute the operation
97
97
2. If successful, return the result
98
98
3. If failed and this was not the final attempt:
99
-
- Call the `strategy` closure with the error
100
-
- If strategy returns `.stop`, rethrow the error immediately
101
-
- If strategy returns `.backoff`, suspend for the given duration
102
-
- Return to step 1
99
+
- Call the `strategy` closure with the error
100
+
- If the strategy returns `.stop`, rethrow the error immediately
101
+
- If the strategy returns `.backoff`, suspend for the given duration
102
+
- Return to step 1
103
103
4. If failed on the final attempt, rethrow the error without consulting the strategy
104
104
105
-
Given this sequence, there is a total of four termination conditions (when retrying will be stopped):
105
+
Given this sequence, there are four termination conditions (when retrying will be stopped):
106
106
- The operation completes without throwing an error
107
107
- The operation has been attempted `maxAttempts` times
108
108
- The strategy closure returns `.stop`
109
-
- The given clock throws
109
+
- The clock throws
110
110
111
111
#### Cancellation
112
112
113
-
`retry` does not introduce special cancellation handling. If your code cooperatively cancels by throwing, ensure your strategy returns `.stop` for that error. Otherwise, retries will continue unless the given clock throws on cancellation (which, at the time of writing, both `ContinuousClock` and `SuspendingClock` do).
113
+
`retry` does not introduce special cancellation handling. If your code cooperatively cancels by throwing, ensure your strategy returns `.stop` for that error. Otherwise, retries continue unless the clock throws on cancellation (which, at the time of writing, both `ContinuousClock` and `SuspendingClock` do).
114
114
115
115
### Backoff
116
116
@@ -126,20 +126,20 @@ var backoff = Backoff
126
126
127
127
Adopters may choose to create their own strategies. There is no requirement to conform to `BackoffStrategy`, since retry and backoff are decoupled; however, to use the provided modifiers (`minimum`, `maximum`, `jitter`), a strategy must conform.
128
128
129
-
Each call to `nextDuration()` returns the delay for the next retry attempt. Strategies are naturally stateful. For instance they may track the number of invocations or the previously returned duration to calculate the next delay.
129
+
Each call to `nextDuration()` returns the delay for the next retry attempt. Strategies are naturally stateful. For instance, they may track the number of invocations or the previously returned duration to calculate the next delay.
130
130
131
131
#### Standard backoff
132
132
133
133
As previously mentioned this proposal introduces several common backoff strategies which include:
(For demonstration purposes only, a network server is used as remote system)
186
+
(For demonstration purposes only, a network server is used as the remote system.)
186
187
187
188
## Effect on API resilience
188
189
189
-
This proposal introduces purely additive API with no impact on existing functionality or API resilience.
190
+
This proposal introduces a purely additive API with no impact on existing functionality or API resilience.
190
191
191
192
## Future directions
192
193
193
194
The jitter variants introduced by this proposal support custom `RandomNumberGenerator` by **copying** it in order to perform the necessary mutations.
194
-
This is not optimal and does not match the standard libraries signatures of e.g. `shuffle()` or `randomElement()` which take an **`inout`** random number generator.
195
-
Due to the composability of backoff algorithms proposed, this is not possible to adopt in current Swift.
196
-
If Swift at one point gains the capability to "store" `inout` variables the jitter variants should try to adopt this by introducing new `inout` overloads and deprecating the copying overloads.
195
+
This is not optimal and does not match the standard library's signatures of e.g. `shuffle()` or `randomElement()` which take an **`inout`** random number generator.
196
+
Due to the composability of backoff algorithms proposed here, this is not possible to adopt in current Swift.
197
+
If Swift gains the capability to "store" `inout` variables, the jitter variants should adopt this by adding new `inout` overloads and deprecating the copying overloads.
197
198
198
199
## Alternatives considered
199
200
@@ -202,4 +203,4 @@ why you chose this approach instead.
202
203
203
204
## Acknowledgments
204
205
205
-
Thanks to [Philippe Hausler](https://github.com/phausler), [Franz Busch](https://github.com/FranzBusch) and [Honza Dvorsky](https://github.com/czechboy0) for their thoughtful feedback and suggestions that helped refine the API design and improve its clarity and usability.
206
+
Thanks to [Philippe Hausler](https://github.com/phausler), [Franz Busch](https://github.com/FranzBusch) and [Honza Dvorsky](https://github.com/czechboy0) for their thoughtful feedback and suggestions that helped refine the API design and improve its clarity and usability.
0 commit comments