Skip to content

Commit 5395513

Browse files
committed
strategy got stand alone package
1 parent e3f18ec commit 5395513

File tree

6 files changed

+10
-148
lines changed

6 files changed

+10
-148
lines changed

Package.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ let package = Package(
1414
],
1515
dependencies: [
1616
// Dependencies declare other packages that this package depends on.
17-
// .package(url: /* package url */, from: "1.0.0"),
17+
.package(url: "https://github.com/The-Igor/retry-policy-service.git", from: "1.0.0"),
1818
],
1919
targets: [
2020
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
2121
// Targets can depend on other targets in this package, and on products in packages this package depends on.
2222
.target(
2323
name: "async-http-client",
24-
dependencies: []),
24+
dependencies: [
25+
.product(name: "retry-policy-service", package: "retry-policy-service"),
26+
]),
2527
.testTarget(
2628
name: "async-http-clientTests",
2729
dependencies: ["async-http-client"]),

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ Network layer for running requests like GET, POST, PUT, DELETE etc customizable
7979
| type | description |
8080
| --- | --- |
8181
| constant | The strategy implements constant backoff |
82-
| exponential | The strategy implements exponential backoff |
82+
| exponential [default] | The strategy implements exponential backoff |
8383

84+
for more details [retry service](https://github.com/The-Igor/retry-policy-service)
8485

8586
# The concept
8687

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//
66

77
import Foundation
8-
8+
import retry_policy_service
99

1010
public extension Http{
1111

@@ -47,7 +47,7 @@ public extension Http{
4747
{
4848

4949
let request = try buildURLRequest(for: path, query: query, headers: headers)
50-
let strategy = RetryService.Strategy.exponential(retry: retry, duration: 2)
50+
let strategy = RetryService.Strategy.exponential(retry: retry)
5151

5252
return try await send(with: request, retry: strategy, taskDelegate)
5353
}
@@ -169,17 +169,16 @@ private extension Http.Proxy{
169169
let session = config.getSession
170170
let service = RetryService(strategy: strategy)
171171

172-
for delay in service{
172+
for delay in service.dropLast(){
173173
do{
174-
print(delay)
175174
return try await session.data(for: request, delegate: taskDelegate)
176175
}catch{
177176
#if DEBUG
178177
print("retry send \(delay)")
179178
#endif
180179
}
181180

182-
try? await Task.sleep(nanoseconds: 1_000_000_000 * UInt64(delay))
181+
try? await Task.sleep(nanoseconds: delay)
183182
}
184183

185184
#if DEBUG

Sources/async-http-client/proxy/http/retry/RetryIterator.swift

-52
This file was deleted.

Sources/async-http-client/proxy/http/retry/RetryService.swift

-44
This file was deleted.

Sources/async-http-client/proxy/http/retry/Strategy.swift

-44
This file was deleted.

0 commit comments

Comments
 (0)