Skip to content

Commit cc7d2db

Browse files
committed
fix: typo in docs
1 parent 1ef7216 commit cc7d2db

File tree

2 files changed

+8
-37
lines changed

2 files changed

+8
-37
lines changed

Sources/Retry/Retry.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public enum RetryStrategy<C> where C: Clock {
100100
/// }
101101
///
102102
/// let (data, response) = try await retry {
103-
/// let (data, response) = try await URLSession.shared.data(from: URL(string: "")!)
103+
/// let (data, response) = try await URLSession.shared.data(from: url)
104104
///
105105
/// if
106106
/// let response = response as? HTTPURLResponse,
@@ -129,7 +129,7 @@ public enum RetryStrategy<C> where C: Clock {
129129
/// - clock: The clock used to wait for delays between retries.
130130
/// - isolation: The inherited actor isolation.
131131
/// - operation: The asynchronous operation to perform. This function will retry the operation in case of error, based on the retry strategy provided.
132-
/// - strategy: A closure that determines the `RetryStrategy` for handling errors based on the error type. Defaults to `.backoff(.none)`, meaning no delay between retries.
132+
/// - strategy: A closure that determines the `RetryStrategy` for handling retries based on the error type. Defaults to `.backoff(.none)`, meaning no delay between retries.
133133
///
134134
/// - Returns: The result of the operation, if successful within the allowed number of attempts.
135135
/// - Throws: Rethrows the last encountered error if all retry attempts fail or if the retry strategy specifies stopping retries or any error thrown by `clock`
@@ -203,7 +203,7 @@ public func retry<R, E, C>(
203203
/// }
204204
///
205205
/// let (data, response) = try await retry {
206-
/// let (data, response) = try await URLSession.shared.data(from: URL(string: "")!)
206+
/// let (data, response) = try await URLSession.shared.data(from: url)
207207
///
208208
/// if
209209
/// let response = response as? HTTPURLResponse,
@@ -231,7 +231,7 @@ public func retry<R, E, C>(
231231
/// - tolerance: An optional tolerance for the delay duration to account for clock imprecision. Defaults to `nil`.
232232
/// - isolation: The inherited actor isolation.
233233
/// - operation: The asynchronous operation to perform. This function will retry the operation in case of error, based on the retry strategy provided.
234-
/// - strategy: A closure that determines the `RetryStrategy` for handling errors based on the error type. Defaults to `.backoff(.none)`, meaning no delay between retries.
234+
/// - strategy: A closure that determines the `RetryStrategy` for handling retries based on the error type. Defaults to `.backoff(.none)`, meaning no delay between retries.
235235
///
236236
/// - Returns: The result of the operation, if successful within the allowed number of attempts.
237237
/// - Throws: Rethrows the last encountered error if all retry attempts fail or if the retry strategy specifies stopping retries or any error thrown by `ContinuousClock`
@@ -286,7 +286,7 @@ public func retry<R, E>(
286286
/// }
287287
///
288288
/// let (data, response) = try await retry {
289-
/// let (data, response) = try await URLSession.shared.data(from: URL(string: "")!)
289+
/// let (data, response) = try await URLSession.shared.data(from: url)
290290
///
291291
/// if
292292
/// let response = response as? HTTPURLResponse,
@@ -314,7 +314,7 @@ public func retry<R, E>(
314314
/// - tolerance: An optional tolerance for the delay duration to account for clock imprecision. Defaults to `nil`.
315315
/// - clock: The clock used to wait for delays between retries.
316316
/// - operation: The asynchronous operation to perform. This function will retry the operation in case of error, based on the retry strategy provided.
317-
/// - strategy: A closure that determines the `RetryStrategy` for handling errors based on the error type. Defaults to `.backoff(.none)`, meaning no delay between retries.
317+
/// - strategy: A closure that determines the `RetryStrategy` for handling retries based on the error type. Defaults to `.backoff(.none)`, meaning no delay between retries.
318318
///
319319
/// - Returns: The result of the operation, if successful within the allowed number of attempts.
320320
/// - Throws: Rethrows the last encountered error if all retry attempts fail or if the retry strategy specifies stopping retries or any error thrown by `clock`
@@ -387,7 +387,7 @@ public func retry<R, C>(
387387
/// }
388388
///
389389
/// let (data, response) = try await retry {
390-
/// let (data, response) = try await URLSession.shared.data(from: URL(string: "")!)
390+
/// let (data, response) = try await URLSession.shared.data(from: url)
391391
///
392392
/// if
393393
/// let response = response as? HTTPURLResponse,
@@ -414,7 +414,7 @@ public func retry<R, C>(
414414
/// - maxAttempts: The maximum number of attempts to retry the operation. Defaults to 3.
415415
/// - tolerance: An optional tolerance for the delay duration to account for clock imprecision. Defaults to `nil`.
416416
/// - operation: The asynchronous operation to perform. This function will retry the operation in case of error, based on the retry strategy provided.
417-
/// - strategy: A closure that determines the `RetryStrategy` for handling errors based on the error type. Defaults to `.backoff(.none)`, meaning no delay between retries.
417+
/// - strategy: A closure that determines the `RetryStrategy` for handling retries based on the error type. Defaults to `.backoff(.none)`, meaning no delay between retries.
418418
///
419419
/// - Returns: The result of the operation, if successful within the allowed number of attempts.
420420
/// - Throws: Rethrows the last encountered error if all retry attempts fail or if the retry strategy specifies stopping retries or any error thrown by `ContinuousClock`

Tests/RetryTests/RetryTests.swift

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -148,32 +148,3 @@ struct CustomError: Error { }
148148
#expect(counter.value == 1)
149149
}
150150
#endif
151-
152-
import Foundation
153-
func idk() async throws {
154-
155-
struct TooManyRequests: Error {
156-
let retryAfter: Double
157-
}
158-
159-
let (data, response) = try await retry(maxAttempts: 5) {
160-
let (data, response) = try await URLSession.shared.data(from: URL(string: "")!)
161-
162-
if
163-
let response = response as? HTTPURLResponse,
164-
let retryAfter = response.value(forHTTPHeaderField: "Retry-After").flatMap(Double.init),
165-
response.statusCode == 429
166-
{
167-
throw TooManyRequests(retryAfter: retryAfter)
168-
}
169-
170-
return (data, response)
171-
} strategy: { error in
172-
173-
if let error = error as? TooManyRequests {
174-
return .backoff(.constant(c: .seconds(error.retryAfter)))
175-
} else {
176-
return .stop
177-
}
178-
}
179-
}

0 commit comments

Comments
 (0)