-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release `1.1.0`
- Loading branch information
Showing
10 changed files
with
214 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,14 +24,17 @@ | |
|
||
## Usage | ||
|
||
`Typhoon` provides two retry policy strategies: | ||
`Typhoon` provides three retry policy strategies: | ||
|
||
```swift | ||
/// A retry strategy with a constant number of attempts and fixed duration between retries. | ||
case constant(retry: Int, duration: DispatchTimeInterval) | ||
|
||
/// A retry strategy with an exponential increase in duration between retries. | ||
case exponential(retry: Int, multiplier: Double, duration: DispatchTimeInterval) | ||
case exponential(retry: Int, multiplier: Double = 2.0, duration: DispatchTimeInterval) | ||
|
||
/// A retry strategy with exponential increase in duration between retries and added jitter. | ||
case exponentialWithJitter(retry: Int, jitterFactor: Double = 0.1, maxInterval: UInt64? = 60, multiplier: Double = 2.0, duration: DispatchTimeInterval) | ||
``` | ||
|
||
Create a `RetryPolicyService` instance and pass a desired strategy like this: | ||
|
@@ -87,4 +90,4 @@ Please feel free to help out with this project! If you see something that could | |
Nikita Vasilev, [email protected] | ||
|
||
## License | ||
typhoon is available under the MIT license. See the LICENSE file for more info. | ||
typhoon is available under the MIT license. See the LICENSE file for more info. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
Tests/TyphoonTests/UnitTests/RetryPolicyStrategyTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// Typhoon | ||
// Copyright © 2023 Space Code. All rights reserved. | ||
// | ||
|
||
import Typhoon | ||
import XCTest | ||
|
||
// MARK: - RetryPolicyStrategyTests | ||
|
||
final class RetryPolicyStrategyTests: XCTestCase { | ||
// MARK: Tests | ||
|
||
func test_thatRetryPolicyStrategyReturnsDuration_whenTypeIsConstant() { | ||
// when | ||
let duration = RetryPolicyStrategy.constant(retry: .retry, duration: .second).duration | ||
|
||
// then | ||
XCTAssertEqual(duration, .second) | ||
} | ||
|
||
func test_thatRetryPolicyStrategyReturnsDuration_whenTypeIsExponential() { | ||
// when | ||
let duration = RetryPolicyStrategy.exponential(retry: .retry, duration: .second).duration | ||
|
||
// then | ||
XCTAssertEqual(duration, .second) | ||
} | ||
|
||
func test_thatRetryPolicyStrategyReturnsDuration_whenTypeIsExponentialWithJitter() { | ||
// when | ||
let duration = RetryPolicyStrategy.exponentialWithJitter(retry: .retry, duration: .second).duration | ||
|
||
// then | ||
XCTAssertEqual(duration, .second) | ||
} | ||
} | ||
|
||
// MARK: Constants | ||
|
||
private extension Int { | ||
static let retry = 5 | ||
} | ||
|
||
private extension DispatchTimeInterval { | ||
static let second = DispatchTimeInterval.seconds(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters