Skip to content

Commit

Permalink
Merge pull request #12 from AlaskaAirlines/kv/timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnavarma1 authored Jan 4, 2024
2 parents 6f02530 + a75f620 commit 80715af
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Example/Shared/Global/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import Foundation

/// Global instance of Atom networking library.
let atom: Atom = {
let configuration = ServiceConfiguration(multipathServiceType: .handover)
let timeout = ServiceConfiguration.Timeout(request: 60, resource: 60)
let configuration = ServiceConfiguration(multipathServiceType: .handover, timeout: timeout)
let atom = Atom(serviceConfiguration: configuration)
atom.log = true

Expand Down
15 changes: 12 additions & 3 deletions Framework/Atom/Service/ServiceConfiguration+Timeout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@

import Foundation

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

/// The maximum amount of time that a resource request should be allowed to take.
internal let resource = 30.0
internal var resource: Double

/// Object to set `URLSessionConfiguration` timeouts
/// - Parameters:
/// - request: Double - The timeout interval to use when waiting for additional data.
/// - resource: Double - The maximum amount of time that a resource request should be allowed to take.
public init(request: Double = 30.0, resource: Double = 30.0) {
self.request = request
self.resource = resource
}
}
}
11 changes: 7 additions & 4 deletions Framework/Atom/Service/ServiceConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ public final class ServiceConfiguration {
/// - decoder: The `JSONDecoder` for decoding data into models.
/// - dispatchQueue: The queue to dispatch `Result` object on.
/// - multipathServiceType: The service type that specifies the Multipath TCP connection policy for transmitting data over Wi-Fi and cellular interfaces.
public init(authenticationMethod: AuthenticationMethod = .none, configuration: Configuration = .ephemeral, decoder: JSONDecoder = JSONDecoder(), dispatchQueue: DispatchQueue = .main, multipathServiceType: MultipathServiceType = .none) {
/// - timeout: Timeout interval needed for URLSessionConfiguration.

public init(authenticationMethod: AuthenticationMethod = .none, configuration: Configuration = .ephemeral, decoder: JSONDecoder = JSONDecoder(), dispatchQueue: DispatchQueue = .main, multipathServiceType: MultipathServiceType = .none, timeout: Timeout = Timeout()) {
self.authenticationMethod = authenticationMethod
self.configuration = configuration
self.decoder = decoder
self.dispatchQueue = dispatchQueue
self.multipathServiceType = multipathServiceType
self.timeout = Timeout()
self.timeout = timeout
}

#else
Expand All @@ -92,12 +94,13 @@ public final class ServiceConfiguration {
/// - configuration: The `ServiceConfiguration.Configuration` - default value is `.ephemeral`.
/// - decoder: The `JSONDecoder` for decoding data into models.
/// - dispatchQueue: The queue to dispatch `Result` object on.
public init(authenticationMethod: AuthenticationMethod = .none, configuration: Configuration = .ephemeral, decoder: JSONDecoder = JSONDecoder(), dispatchQueue: DispatchQueue = .main) {
/// - timeout: Timeout interval needed for URLSessionConfiguration.
public init(authenticationMethod: AuthenticationMethod = .none, configuration: Configuration = .ephemeral, decoder: JSONDecoder = JSONDecoder(), dispatchQueue: DispatchQueue = .main, timeout: Timeout = Timeout()) {
self.authenticationMethod = authenticationMethod
self.configuration = configuration
self.decoder = decoder
self.dispatchQueue = dispatchQueue
self.timeout = Timeout()
self.timeout = timeout
}
#endif
}
Expand Down
11 changes: 11 additions & 0 deletions Framework/AtomTests/Models/ServiceConfigurationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@ internal class ServiceConfigurationTests: BaseCase {
XCTAssertEqual(serviceConfiguration.dispatchQueue, .main)
XCTAssertEqual(serviceConfiguration.configuration, .ephemeral)
}

internal func testServiceConfigurationInitializationWithTimeout() {
// Given, When
let timeout = ServiceConfiguration.Timeout(request: 60, resource: 60)
let serviceConfiguration = ServiceConfiguration(timeout: timeout)

// Then
XCTAssertEqual(serviceConfiguration.timeout.request, 60)
XCTAssertEqual(serviceConfiguration.timeout.resource, 60)
}

}

0 comments on commit 80715af

Please sign in to comment.