Skip to content

Commit 5865671

Browse files
authored
Release 1.2.1 (#20)
Release `1.2.1`
2 parents 0ce7cc3 + 85549fa commit 5865671

File tree

5 files changed

+60
-21
lines changed

5 files changed

+60
-21
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
All notable changes to this project will be documented in this file.
33

44
#### 1.x Releases
5-
- `1.2.x` Releases - [1.2.0](#120)
5+
- `1.2.x` Releases - [1.2.0](#120) | [1.2.1](#121)
66
- `1.1.x` Releases - [1.1.0](#110) | [1.1.1](#111)
77
- `1.0.x` Releases - [1.0.0](#100)
88

9+
## [1.2.1](https://github.com/space-code/typhoon/releases/tag/1.2.1)
10+
11+
#### Added
12+
- Mark the closures as @Sendable.
13+
- Added in Pull Request [#18](https://github.com/space-code/typhoon/pull/18)
14+
915
## [1.2.0](https://github.com/space-code/typhoon/releases/tag/1.2.0)
1016

1117
#### Added
@@ -44,4 +50,4 @@ Released on 2023-11-10.
4450

4551
#### Added
4652
- Initial release of Typhoon.
47-
- Added by [Nikita Vasilev](https://github.com/nik3212).
53+
- Added by [Nikita Vasilev](https://github.com/nik3212).

Sources/Typhoon/Classes/RetryPolicyService/IRetryPolicyService.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//
22
// Typhoon
3-
// Copyright © 2023 Space Code. All rights reserved.
3+
// Copyright © 2024 Space Code. All rights reserved.
44
//
55

66
import Foundation
77

88
// MARK: - IRetryPolicyService
99

1010
/// A type that defines a service for retry policies
11-
public protocol IRetryPolicyService {
11+
public protocol IRetryPolicyService: Sendable {
1212
/// Retries a closure with a given strategy.
1313
///
1414
/// - Parameters:
@@ -19,8 +19,8 @@ public protocol IRetryPolicyService {
1919
/// - Returns: The result of the closure's execution after retrying based on the policy.
2020
func retry<T>(
2121
strategy: RetryPolicyStrategy?,
22-
onFailure: ((Error) async -> Void)?,
23-
_ closure: () async throws -> T
22+
onFailure: (@Sendable (Error) async -> Void)?,
23+
_ closure: @Sendable () async throws -> T
2424
) async throws -> T
2525
}
2626

@@ -31,7 +31,7 @@ public extension IRetryPolicyService {
3131
/// - closure: The closure that will be retried based on the specified strategy.
3232
///
3333
/// - Returns: The result of the closure's execution after retrying based on the policy.
34-
func retry<T>(_ closure: () async throws -> T) async throws -> T {
34+
func retry<T>(_ closure: @Sendable () async throws -> T) async throws -> T {
3535
try await retry(strategy: nil, onFailure: nil, closure)
3636
}
3737

@@ -42,7 +42,7 @@ public extension IRetryPolicyService {
4242
/// - closure: The closure that will be retried based on the specified strategy.
4343
///
4444
/// - Returns: The result of the closure's execution after retrying based on the policy.
45-
func retry<T>(strategy: RetryPolicyStrategy?, _ closure: () async throws -> T) async throws -> T {
45+
func retry<T>(strategy: RetryPolicyStrategy?, _ closure: @Sendable () async throws -> T) async throws -> T {
4646
try await retry(strategy: strategy, onFailure: nil, closure)
4747
}
4848
}

Sources/Typhoon/Classes/RetryPolicyService/RetryPolicyService.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// Typhoon
3-
// Copyright © 2023 Space Code. All rights reserved.
3+
// Copyright © 2024 Space Code. All rights reserved.
44
//
55

66
import Foundation
@@ -29,8 +29,8 @@ public final class RetryPolicyService {
2929
extension RetryPolicyService: IRetryPolicyService {
3030
public func retry<T>(
3131
strategy: RetryPolicyStrategy?,
32-
onFailure: ((Error) async -> Void)?,
33-
_ closure: () async throws -> T
32+
onFailure: (@Sendable (Error) async -> Void)?,
33+
_ closure: @Sendable () async throws -> T
3434
) async throws -> T {
3535
for duration in RetrySequence(strategy: strategy ?? self.strategy) {
3636
try Task.checkCancellation()

Sources/Typhoon/Classes/Strategy/RetryPolicyStrategy.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//
22
// Typhoon
3-
// Copyright © 2023 Space Code. All rights reserved.
3+
// Copyright © 2024 Space Code. All rights reserved.
44
//
55

66
import Foundation
77

88
/// A strategy used to define different retry policies.
9-
public enum RetryPolicyStrategy {
9+
public enum RetryPolicyStrategy: Sendable {
1010
/// A retry strategy with a constant number of attempts and fixed duration between retries.
1111
///
1212
/// - Parameters:

Tests/TyphoonTests/UnitTests/RetryPolicyServiceTests.swift

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// Typhoon
3-
// Copyright © 2023 Space Code. All rights reserved.
3+
// Copyright © 2024 Space Code. All rights reserved.
44
//
55

66
import Typhoon
@@ -42,39 +42,72 @@ final class RetryPolicyServiceTests: XCTestCase {
4242

4343
func test_thatRetryServiceDoesNotThrowAnError_whenServiceDidReturnValue() async throws {
4444
// given
45-
var counter = 0
45+
actor Counter {
46+
// MARK: Properties
47+
48+
private var value: Int = 0
49+
50+
// MARK: Internal
51+
52+
func increment() -> Int {
53+
value += 1
54+
return value
55+
}
56+
}
57+
58+
let counter = Counter()
4659

4760
// when
4861
_ = try await sut.retry(
4962
strategy: .constant(retry: .retry, duration: .nanoseconds(1)),
5063
{
51-
counter += 1
64+
let currentCounter = await counter.increment()
5265

53-
if counter > .retry - 1 {
66+
if currentCounter > .retry - 1 {
5467
return 1
5568
}
5669
throw URLError(.unknown)
5770
}
5871
)
5972

6073
// then
61-
XCTAssertEqual(counter, .retry)
74+
let finalValue = await counter.increment() - 1
75+
XCTAssertEqual(finalValue, .retry)
6276
}
6377

6478
func test_thatRetryServiceHandlesErrorOnFailureCallback_whenErrorOcurred() async {
79+
// given
80+
actor ErrorContainer {
81+
// MARK: Private
82+
83+
private var error: NSError?
84+
85+
// MARK: Internal
86+
87+
func setError(_ newError: NSError) {
88+
error = newError
89+
}
90+
91+
func getError() -> NSError? {
92+
error
93+
}
94+
}
95+
96+
let errorContainer = ErrorContainer()
97+
6598
// when
66-
var failureError: NSError?
6799
do {
68100
_ = try await sut.retry(
69101
strategy: .constant(retry: .retry, duration: .nanoseconds(1)),
70-
onFailure: { error in failureError = error as NSError }
102+
onFailure: { error in await errorContainer.setError(error as NSError) }
71103
) {
72104
throw URLError(.unknown)
73105
}
74106
} catch {}
75107

76108
// then
77-
XCTAssertEqual(failureError as? URLError, URLError(.unknown))
109+
let capturedError = await errorContainer.getError()
110+
XCTAssertEqual(capturedError as? URLError, URLError(.unknown))
78111
}
79112
}
80113

0 commit comments

Comments
 (0)