2

I could not find any way to cancel a request using Siesta Framework. Is this possible, and how?

o15a3d4l11s2
  • 3,969
  • 3
  • 29
  • 40

1 Answers1

1

I found that there is a method cancel(), which should be called on the Request object. As documented, it is not guaranteed to really cancel the request if it is already started, but it will at least ignore the result and send you a completion/failure, which you can then handle accordingly.

Example:

let siestaRequest = MyAPI.profile.request(.post, json: ["foo": [1,2,3]])
// when needed, later
siestaRequest.cancel()
o15a3d4l11s2
  • 3,969
  • 3
  • 29
  • 40
  • 1
    Note that _no_ network framework can guarantee that a request will be cancelled if it’s already started. Once packets have started going to the server, you’re in race condition territory and all guarantees are off. – Paul Cantrell Feb 05 '17 at 17:11
  • @PaulCantrell, thanks for the clarification. I did not mean the answer to sound like a complaint. I was looking for the cancellation method as I could not find an example. Since I found it in the classes of the library, I just wanted to write it down. – o15a3d4l11s2 Feb 05 '17 at 17:26
  • 1
    No offense taken. Just wanted to note the general need for caution when making assumptions about cancelled network requests. – Paul Cantrell Feb 06 '17 at 01:33