Skip to content

Commit

Permalink
Add timeoutInterval property
Browse files Browse the repository at this point in the history
  • Loading branch information
Bunn committed Sep 19, 2020
1 parent 3b19186 commit e111a63
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Sources/SwiftHole/Service/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation

internal struct Service {

var timeoutInterval: TimeInterval = 30

// MARK: Public Methods

Expand Down Expand Up @@ -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))
Expand Down
14 changes: 12 additions & 2 deletions Sources/SwiftHole/SwiftHole.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation

private enum EnableDisableMethodType {
case enable
Expand All @@ -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)
}

Expand Down

0 comments on commit e111a63

Please sign in to comment.