Skip to content

Commit 1fe81fd

Browse files
committed
Add more detail to the Overview section of the documentation landing page.
1 parent 76ded67 commit 1fe81fd

3 files changed

Lines changed: 43 additions & 16 deletions

File tree

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ Retries in Swift with sensible defaults and powerful flexibility.
77
![MIT License](https://img.shields.io/github/license/fumoboy007/swift-retry)
88
![Automated Tests Workflow Status](https://img.shields.io/github/actions/workflow/status/fumoboy007/swift-retry/tests.yml?event=push&label=tests)
99

10-
## Features
11-
12-
- Designed for [Swift Concurrency](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/concurrency/).
13-
- Sensible default retry behavior.
14-
- Flexible enough for any use case.
15-
- Comprehensive tests and documentation.
16-
1710
## Basic Usage
1811

1912
```swift
@@ -22,4 +15,24 @@ try await retry {
2215
}
2316
```
2417

25-
See the [documentation](https://fumoboy007.github.io/swift-retry/documentation/retry/) for examples of more sophisticated use cases.
18+
See the [documentation](https://fumoboy007.github.io/swift-retry/documentation/retry/) for examples of more advanced use cases.
19+
20+
## Overview
21+
22+
### Designed for Swift Concurrency
23+
24+
The `retry` function is an `async` function that runs the given `async` closure repeatedly until it succeeds or until the failure is no longer retryable. The function sleeps in between attempts while respecting task cancellation.
25+
26+
### Sensible Defaults
27+
28+
The library uses similar defaults as [Amazon Web Services](https://docs.aws.amazon.com/sdkref/latest/guide/feature-retry-behavior.html) and [Google Cloud](https://github.com/googleapis/gax-go/blob/465d35f180e8dc8b01979d09c780a10c41f15136/v2/call_option.go#L181-L205).
29+
30+
An important but often overlooked default is the choice of backoff algorithm, which determines how long to sleep in between attempts. This library chooses an [exponential backoff](https://en.wikipedia.org/wiki/Exponential_backoff) algorithm by default, which is suitable for most use cases. Most retry use cases involve a resource, such as a server, with potentially many clients where an exponential backoff algorithm would be ideal to avoid [DDoSing the resource](https://cloud.google.com/blog/products/gcp/how-to-avoid-a-self-inflicted-ddos-attack-cre-life-lessons).
31+
32+
### Powerful Flexibility
33+
34+
The API provides several customization points to accommodate any use case:
35+
- Retries can be selectively enabled or disabled for specific error cases by providing a custom `shouldRetry` closure. Retries can also be selectively enabled or disabled for specific code paths by wrapping thrown errors with `Retryable` or `NotRetryable`.
36+
- The `RetryConfiguration` type encapsulates the retry behavior so that it can be reused across multiple call sites without duplicating code.
37+
- The `Backoff` type represents the choice of algorithm that will be used to determine how long to sleep in between attempts. It has built-in support for common algorithms but can be initialized with a custom `BackoffAlgorithm` implementation if needed.
38+
- The clock that is used to sleep in between attempts can be replaced. For example, one might use a fake `Clock` implementation in automated tests to ensure the tests are deterministic and efficient.

Sources/Retry/Backoff/Backoff.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public struct Backoff<ClockType: Clock> {
2626

2727
/// The default algorithm, which is suitable for most use cases.
2828
///
29-
/// This algorithm is an exponential backoff algorithm. The specific choice of algorithm is an implementation
30-
/// detail, which may change in the future.
29+
/// This algorithm is an [exponential backoff](https://en.wikipedia.org/wiki/Exponential_backoff) algorithm.
30+
/// The specific choice of algorithm is an implementation detail, which may change in the future.
3131
///
3232
/// - Parameters:
3333
/// - baseDelay: A duration that all delays will be based on. For example, in a simple exponential
@@ -43,8 +43,8 @@ public struct Backoff<ClockType: Clock> {
4343

4444
/// Exponential backoff with “full jitter”.
4545
///
46-
/// This algorithm is used by [AWS](https://docs.aws.amazon.com/sdkref/latest/guide/feature-retry-behavior.html#feature-retry-behavior-sdk-compat)
47-
/// and [Google Cloud](https://github.com/googleapis/gax-go/blob/465d35f180e8dc8b01979d09c780a10c41f15136/v2/call_option.go#L181-L205),
46+
/// This algorithm is used by [AWS](https://docs.aws.amazon.com/sdkref/latest/guide/feature-retry-behavior.html) and
47+
/// [Google Cloud](https://github.com/googleapis/gax-go/blob/465d35f180e8dc8b01979d09c780a10c41f15136/v2/call_option.go#L181-L205),
4848
/// among others. The advantages and disadvantages of the algorithm are detailed in a [blog post](https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/)
4949
/// by AWS.
5050
///
@@ -69,7 +69,7 @@ public struct Backoff<ClockType: Clock> {
6969
///
7070
/// - Warning: This algorithm should only be used as an optimization for a small set of use cases.
7171
/// Most retry use cases involve a resource, such as a server, with potentially many clients where an
72-
/// exponential backoff algorithm would be ideal to avoid [DDoSing the server](https://cloud.google.com/blog/products/gcp/how-to-avoid-a-self-inflicted-ddos-attack-cre-life-lessons).
72+
/// exponential backoff algorithm would be ideal to avoid [DDoSing the resource](https://cloud.google.com/blog/products/gcp/how-to-avoid-a-self-inflicted-ddos-attack-cre-life-lessons).
7373
/// The constant delay algorithm should only be used in cases where there is no possibility of a DDoS.
7474
///
7575
/// - Parameter delay: The constant duration to sleep in between attempts.

Sources/Retry/Retry.docc/Retry.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,23 @@ Retries with sensible defaults and powerful flexibility.
44

55
## Overview
66

7-
- Designed for [Swift Concurrency](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/concurrency/).
8-
- Sensible default retry behavior.
9-
- Flexible enough for any use case.
7+
### Designed for Swift Concurrency
8+
9+
The ``retry(maxAttempts:backoff:appleLogger:logger:operation:shouldRetry:)`` function is an `async` function that runs the given `async` closure repeatedly until it succeeds or until the failure is no longer retryable. The function sleeps in between attempts while respecting task cancellation.
10+
11+
### Sensible Defaults
12+
13+
The library uses similar defaults as [Amazon Web Services](https://docs.aws.amazon.com/sdkref/latest/guide/feature-retry-behavior.html) and [Google Cloud](https://github.com/googleapis/gax-go/blob/465d35f180e8dc8b01979d09c780a10c41f15136/v2/call_option.go#L181-L205).
14+
15+
An important but often overlooked default is the choice of backoff algorithm, which determines how long to sleep in between attempts. This library chooses an [exponential backoff](https://en.wikipedia.org/wiki/Exponential_backoff) algorithm by default, which is suitable for most use cases. Most retry use cases involve a resource, such as a server, with potentially many clients where an exponential backoff algorithm would be ideal to avoid [DDoSing the resource](https://cloud.google.com/blog/products/gcp/how-to-avoid-a-self-inflicted-ddos-attack-cre-life-lessons).
16+
17+
### Powerful Flexibility
18+
19+
The API provides several customization points to accommodate any use case:
20+
- Retries can be selectively enabled or disabled for specific error cases by providing a custom ``RetryConfiguration/shouldRetry`` closure. Retries can also be selectively enabled or disabled for specific code paths by wrapping thrown errors with ``Retryable`` or ``NotRetryable``.
21+
- The ``RetryConfiguration`` type encapsulates the retry behavior so that it can be reused across multiple call sites without duplicating code.
22+
- The ``Backoff`` type represents the choice of algorithm that will be used to determine how long to sleep in between attempts. It has built-in support for common algorithms but can be initialized with a custom ``BackoffAlgorithm`` implementation if needed.
23+
- The ``RetryConfiguration/clock`` that is used to sleep in between attempts can be replaced. For example, one might use a fake `Clock` implementation in automated tests to ensure the tests are deterministic and efficient.
1024

1125
## Topics
1226

0 commit comments

Comments
 (0)