I want to set different timeouts for different requests. My request routine looks like:
var request = URLRequest(url: url,
cachePolicy: .reloadIgnoringLocalCacheData,
timeoutInterval: timeout)
// setting headers and body...
sessionTask = localURLSession.dataTask(with: request)
sessionTask?.resume()
where localURLSession
is defined as public var:
public var localURLSession: Foundation.URLSession {
return Foundation.URLSession(configuration: localConfig, delegate: self, delegateQueue: nil)
}
public var localConfig: URLSessionConfiguration {
let res = URLSessionConfiguration.default
res.timeoutIntervalForRequest = Self.ordinaryRequestsTimeout // 20 seconds
return res
}
Then I have 2 problems:
- When I make 2 simultaneous requests with 100% loss Network Link Conditioner (first with 20 seconds timeout and second – with 40 seconds), both requests fails after 8 seconds. I don't understand why.
- When I make one request for the first time with 100% loss Network Link Conditioner, it fails in timeout like expected, but retrying this request fails in 1 second. I want to wait all the timeout every time.