Skip to content

Commit

Permalink
add a timeout to the response semaphore
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Keller committed Apr 19, 2017
1 parent 8a028ee commit 0757e88
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Sources/SwiftChatSE/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ open class Client: NSObject, URLSessionDataDelegate {
case invalidURL(url: String)
case notUTF8
case unknownError
case timeout
}


Expand Down Expand Up @@ -338,7 +339,9 @@ open class Client: NSObject, URLSessionDataDelegate {
}


sema.wait()
if sema.wait(timeout: DispatchTime.now() + 30) == .timedOut {
responseError = RequestError.timeout
}
}

guard let response = resp as? HTTPURLResponse, data != nil else {
Expand Down Expand Up @@ -397,7 +400,9 @@ open class Client: NSObject, URLSessionDataDelegate {
sema.signal()
}

sema.wait()
if sema.wait(timeout: DispatchTime.now() + 30) == .timedOut {
responseError = RequestError.timeout
}
}


Expand Down

0 comments on commit 0757e88

Please sign in to comment.