Skip to content

Commit 4eef41c

Browse files
committed
update
1 parent 2eb9c1d commit 4eef41c

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Network layer for running requests like GET, POST, PUT, DELETE etc customizable
6868
/// - taskDelegate: A protocol that defines methods that URL session instances call on their delegates to handle task-level events
6969
func sendRetry(
7070
with request : URLRequest,
71-
retry : Int = 1,
71+
retry : UInt = 1,
7272
_ taskDelegate: ITaskDelegate? = nil
7373
```
7474

Sources/async-http-client/proxy/http/Proxy.swift

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public extension Http{
4040
path: String,
4141
query : Query? = nil,
4242
headers : Headers? = nil,
43-
retry : Int = 1,
43+
retry : UInt = 1,
4444
taskDelegate: ITaskDelegate? = nil
4545
) async throws
4646
-> Http.Response<T> where T: Decodable
@@ -64,7 +64,7 @@ public extension Http{
6464
body : Encodable? = nil,
6565
query : Query? = nil,
6666
headers : Headers? = nil,
67-
retry : Int = 1,
67+
retry : UInt = 1,
6868
taskDelegate: ITaskDelegate? = nil
6969
) async throws
7070
-> Http.Response<T> where T: Decodable
@@ -88,7 +88,7 @@ public extension Http{
8888
body : Encodable? = nil,
8989
query : Query? = nil,
9090
headers : Headers? = nil,
91-
retry : Int = 1,
91+
retry : UInt = 1,
9292
taskDelegate: ITaskDelegate? = nil
9393
) async throws
9494
-> Http.Response<T> where T: Decodable
@@ -109,7 +109,7 @@ public extension Http{
109109
path: String,
110110
query : Query? = nil,
111111
headers : Headers? = nil,
112-
retry : Int = 1,
112+
retry : UInt = 1,
113113
taskDelegate: ITaskDelegate? = nil
114114
) async throws
115115
-> Http.Response<T> where T: Decodable
@@ -127,7 +127,7 @@ public extension Http{
127127
/// - taskDelegate: A protocol that defines methods that URL session instances call on their delegates to handle task-level events
128128
public func send<T>(
129129
with request : URLRequest,
130-
retry : Int = 1,
130+
retry : UInt = 1,
131131
_ taskDelegate: ITaskDelegate? = nil
132132
) async throws -> Http.Response<T> where T : Decodable
133133
{
@@ -154,32 +154,33 @@ private extension Http.Proxy{
154154
/// - taskDelegate: A protocol that defines methods that URL session instances call on their delegates to handle task-level events
155155
func sendRetry(
156156
with request : URLRequest,
157-
retry : Int = 1,
157+
retry : UInt = 1,
158158
_ taskDelegate: ITaskDelegate? = nil
159159
) async throws -> (Data, URLResponse)
160160
{
161-
guard retry > 0 else { throw HttpProxyError.RetryMustBeBiggerThenZero }
162-
163-
let sesstion = config.getSession
164-
var nextDelay: UInt64 = 1
165161

162+
let session = config.getSession
163+
var nextDelay: UInt64 = 1
164+
print(retry)
166165
if retry > 1{
167-
for i in 1...retry-1{
166+
let limit = retry - 1
167+
for i in 1...limit{
168168
do{
169-
return try await sesstion.data(for: request, delegate: taskDelegate)
169+
return try await session.data(for: request, delegate: taskDelegate)
170170
}catch{
171171
#if DEBUG
172172
print("retry \(i)")
173173
#endif
174174
}
175-
175+
// nanoseconds the only choice for iOS15
176176
try? await Task.sleep(nanoseconds: 1_000_000_000 * nextDelay)
177177

178178
nextDelay *= 2
179179
}
180180
}
181-
182-
return try await sesstion.data(for: request, delegate: taskDelegate)
181+
182+
/// one more time to let the error to propagate if it fails the last time
183+
return try await session.data(for: request, delegate: taskDelegate)
183184
}
184185

185186
/// Url builder method

Sources/async-http-client/proxy/http/enum/HttpProxyError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import Foundation
99

10+
/// Set of errors
1011
enum HttpProxyError : Error{
1112

12-
case RetryMustBeBiggerThenZero
1313

1414
}

0 commit comments

Comments
 (0)