2

I am doing a series of web requests using OperationQueue and Alamofire. I get this error only first time after login. From second time onwards this error doesn't come. Below is my request code:

func request<T>(path:String,method:HTTPMethod , parameters:[String:String]? = nil,body:[String:Any]? = nil, completion:@escaping (Alamofire.Result<T>)->()) {
        networkManager.request(url(path: path, params: parameters), method: method, parameters: body, encoding: JSONEncoding.default, headers: _authHeader)
            .response { response in
                if let networkResponse =    response.response{
 //Some Code Here
                }else{
                    completion(response.error)
                }
            }
        }

What is interesting is that this error comes only when I set queue.maxConcurrentOperationCount as something other than 1. Below is the code where I declared OperationQueue

var fetchQueue:OperationQueue = {
    var queue = OperationQueue()
    queue.qualityOfService = .userInitiated
    queue.name = "fetchQueue queue"
    queue.maxConcurrentOperationCount = OperationQueue.defaultMaxConcurrentOperationCount
    return queue
}()

From other posts it is clear that due to another request made, first request is getting canceled. But why only first time? And whats the way out? Without this my web request is sent in series rather than multiple simultaneously.

Amit Gupta
  • 192
  • 2
  • 13

0 Answers0