I need to cancel all the operations in the NSOperationQueue immediately.
Consider my scenario,
I have to hit my server continuously ie I will be calling my server whenever user types in the textbox. After user completes his input I have to hit final api call. So I create one NSOperation for single API hit. While user types in the textbox. I create NSOperation object and add that in NSOperationQueue. After detecting that user completely his input, I cancelled all the operation in the queue and hit my final api. The Problem is some operations are not cancelled immediately. So my final api hit is not called immediately. It is waiting for some time (all operation have to finish) and then it called.
FYI,
myOperationQueue.cancelAllOperations()
In Operation start method I have this code
let session = URLSession.shared
let task = session.dataTask(with: urlRequest, completionHandler: { (data, urlResponse, error) -> Void in
})
task.resume()
Please provide me the best way to call my final API immediately.