Skip to content

Commit e111a63

Browse files
committed
Add timeoutInterval property
1 parent 3b19186 commit e111a63

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Sources/SwiftHole/Service/Service.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Foundation
99

1010
internal struct Service {
1111

12+
var timeoutInterval: TimeInterval = 30
1213

1314
// MARK: Public Methods
1415

@@ -72,6 +73,7 @@ internal struct Service {
7273
var urlRequest = URLRequest(url: url)
7374
urlRequest.httpMethod = router.method
7475
let session = URLSession(configuration: .default)
76+
urlRequest.timeoutInterval = timeoutInterval
7577
let dataTask = session.dataTask(with: urlRequest, completionHandler: { data, response, error in
7678
if let error = error {
7779
completionHandler(nil, nil, .sessionError(error))

Sources/SwiftHole/SwiftHole.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Foundation
12

23
private enum EnableDisableMethodType {
34
case enable
@@ -6,12 +7,21 @@ private enum EnableDisableMethodType {
67

78
public struct SwiftHole {
89
private let environment: Environment
9-
private let service = Service()
10+
private var service = Service()
1011

12+
public var timeoutInterval: TimeInterval {
13+
set {
14+
service.timeoutInterval = newValue
15+
}
16+
get {
17+
return service.timeoutInterval
18+
}
19+
}
1120

1221
// MARK: Public Methods
1322

14-
public init(host: String, port: Int? = nil, apiToken: String? = nil) {
23+
public init(host: String, port: Int? = nil, apiToken: String? = nil, timeoutInterval: TimeInterval = 30) {
24+
service.timeoutInterval = timeoutInterval
1525
environment = Environment(host: host, port: port, apiToken: apiToken)
1626
}
1727

0 commit comments

Comments
 (0)