Skip to content

Commit 80715af

Browse files
Merge pull request #12 from AlaskaAirlines/kv/timeout
2 parents 6f02530 + a75f620 commit 80715af

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

Example/Shared/Global/Constants.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import Foundation
1919

2020
/// Global instance of Atom networking library.
2121
let atom: Atom = {
22-
let configuration = ServiceConfiguration(multipathServiceType: .handover)
22+
let timeout = ServiceConfiguration.Timeout(request: 60, resource: 60)
23+
let configuration = ServiceConfiguration(multipathServiceType: .handover, timeout: timeout)
2324
let atom = Atom(serviceConfiguration: configuration)
2425
atom.log = true
2526

Framework/Atom/Service/ServiceConfiguration+Timeout.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,22 @@
1616

1717
import Foundation
1818

19-
internal extension ServiceConfiguration {
19+
public extension ServiceConfiguration {
2020
/// Model object representing `URLSessionConfiguration` timeout intervals.
2121
struct Timeout {
2222
/// The timeout interval to use when waiting for additional data.
23-
internal let request = 30.0
23+
internal var request: Double
2424

2525
/// The maximum amount of time that a resource request should be allowed to take.
26-
internal let resource = 30.0
26+
internal var resource: Double
27+
28+
/// Object to set `URLSessionConfiguration` timeouts
29+
/// - Parameters:
30+
/// - request: Double - The timeout interval to use when waiting for additional data.
31+
/// - resource: Double - The maximum amount of time that a resource request should be allowed to take.
32+
public init(request: Double = 30.0, resource: Double = 30.0) {
33+
self.request = request
34+
self.resource = resource
35+
}
2736
}
2837
}

Framework/Atom/Service/ServiceConfiguration.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ public final class ServiceConfiguration {
7474
/// - decoder: The `JSONDecoder` for decoding data into models.
7575
/// - dispatchQueue: The queue to dispatch `Result` object on.
7676
/// - multipathServiceType: The service type that specifies the Multipath TCP connection policy for transmitting data over Wi-Fi and cellular interfaces.
77-
public init(authenticationMethod: AuthenticationMethod = .none, configuration: Configuration = .ephemeral, decoder: JSONDecoder = JSONDecoder(), dispatchQueue: DispatchQueue = .main, multipathServiceType: MultipathServiceType = .none) {
77+
/// - timeout: Timeout interval needed for URLSessionConfiguration.
78+
79+
public init(authenticationMethod: AuthenticationMethod = .none, configuration: Configuration = .ephemeral, decoder: JSONDecoder = JSONDecoder(), dispatchQueue: DispatchQueue = .main, multipathServiceType: MultipathServiceType = .none, timeout: Timeout = Timeout()) {
7880
self.authenticationMethod = authenticationMethod
7981
self.configuration = configuration
8082
self.decoder = decoder
8183
self.dispatchQueue = dispatchQueue
8284
self.multipathServiceType = multipathServiceType
83-
self.timeout = Timeout()
85+
self.timeout = timeout
8486
}
8587

8688
#else
@@ -92,12 +94,13 @@ public final class ServiceConfiguration {
9294
/// - configuration: The `ServiceConfiguration.Configuration` - default value is `.ephemeral`.
9395
/// - decoder: The `JSONDecoder` for decoding data into models.
9496
/// - dispatchQueue: The queue to dispatch `Result` object on.
95-
public init(authenticationMethod: AuthenticationMethod = .none, configuration: Configuration = .ephemeral, decoder: JSONDecoder = JSONDecoder(), dispatchQueue: DispatchQueue = .main) {
97+
/// - timeout: Timeout interval needed for URLSessionConfiguration.
98+
public init(authenticationMethod: AuthenticationMethod = .none, configuration: Configuration = .ephemeral, decoder: JSONDecoder = JSONDecoder(), dispatchQueue: DispatchQueue = .main, timeout: Timeout = Timeout()) {
9699
self.authenticationMethod = authenticationMethod
97100
self.configuration = configuration
98101
self.decoder = decoder
99102
self.dispatchQueue = dispatchQueue
100-
self.timeout = Timeout()
103+
self.timeout = timeout
101104
}
102105
#endif
103106
}

Framework/AtomTests/Models/ServiceConfigurationTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,15 @@ internal class ServiceConfigurationTests: BaseCase {
2626
XCTAssertEqual(serviceConfiguration.dispatchQueue, .main)
2727
XCTAssertEqual(serviceConfiguration.configuration, .ephemeral)
2828
}
29+
30+
internal func testServiceConfigurationInitializationWithTimeout() {
31+
// Given, When
32+
let timeout = ServiceConfiguration.Timeout(request: 60, resource: 60)
33+
let serviceConfiguration = ServiceConfiguration(timeout: timeout)
34+
35+
// Then
36+
XCTAssertEqual(serviceConfiguration.timeout.request, 60)
37+
XCTAssertEqual(serviceConfiguration.timeout.resource, 60)
38+
}
39+
2940
}

0 commit comments

Comments
 (0)