Search code examples
swiftalamofire

cancel request when its already finished


consider the following (pseudo) code:

let request = Alamofire.request(...) {
//handler called when requests has been completed
//do some processing here
}

//some processing here, could take a while

request.cancel()

Question:

what happens if the request has already been fully completed (and the handler called) when the request.cancel() is done?

  • Will this return an error?
  • Is the handler called again?
  • Or (what I am hoping for) nothing...?

Solution

  • If the handler called that means request has its answer that can mean two things: Either request is succesfull, you have what you asked or request is not succesfull which means you will get an error.

    Either way if you got your response request.cancel() will mean nothing.