diff --git a/Sources/SwiftHole/Service/Service.swift b/Sources/SwiftHole/Service/Service.swift index 431af54..7c1201f 100644 --- a/Sources/SwiftHole/Service/Service.swift +++ b/Sources/SwiftHole/Service/Service.swift @@ -9,6 +9,7 @@ import Foundation internal struct Service { + var timeoutInterval: TimeInterval = 30 // MARK: Public Methods @@ -72,6 +73,7 @@ internal struct Service { var urlRequest = URLRequest(url: url) urlRequest.httpMethod = router.method let session = URLSession(configuration: .default) + urlRequest.timeoutInterval = timeoutInterval let dataTask = session.dataTask(with: urlRequest, completionHandler: { data, response, error in if let error = error { completionHandler(nil, nil, .sessionError(error)) diff --git a/Sources/SwiftHole/SwiftHole.swift b/Sources/SwiftHole/SwiftHole.swift index 48bfb73..d1069c6 100644 --- a/Sources/SwiftHole/SwiftHole.swift +++ b/Sources/SwiftHole/SwiftHole.swift @@ -1,3 +1,4 @@ +import Foundation private enum EnableDisableMethodType { case enable @@ -6,12 +7,21 @@ private enum EnableDisableMethodType { public struct SwiftHole { private let environment: Environment - private let service = Service() + private var service = Service() + public var timeoutInterval: TimeInterval { + set { + service.timeoutInterval = newValue + } + get { + return service.timeoutInterval + } + } // MARK: Public Methods - public init(host: String, port: Int? = nil, apiToken: String? = nil) { + public init(host: String, port: Int? = nil, apiToken: String? = nil, timeoutInterval: TimeInterval = 30) { + service.timeoutInterval = timeoutInterval environment = Environment(host: host, port: port, apiToken: apiToken) }