Add support for cancelling requests
This potentially could be tricky, as we'd have to handle in-flight requests, the authenticate process, and queued requests waiting for authentication to complete.
Hello :) I am considering using Superb in my project and I've been playing with it for a week and I like its architecture. I am considering rewriting my network layer but I might need to implement this "cancel all requests" feature. Have you thought about it ? Since you have a clearer understanding, you might have some leads to implement this in Superb.
I thought about adding a new "cancelling" state in the CurrentAuthenticationState (maybe not in this struct as it's not a "authentication state" but rather the Authorizer's state), a cancelAll(). Depending on the current state, I would need to empty the channel, cancel the session's request and refusing any other incoming requests.
I also thought about what it would mean to cancel requests and in what context this would be called. For my case, that would be triggered by a user logout and getting rid of the authorizer in a clean way. Any insights since you probably have worked a lot more on that than me and that you might be using Superb in one of your apps ?
Thanks!
@nashfive Good to hear! I hope it works well for you, and would love to hear your feedback from using it.
Here are some high-level thoughts:
-
I had in mind to introduce a simple
Cancelableprotocol, like so:protocol Cancelable { func cancel() } -
I think it would make sense to start with implementing cancellation for just a single request, and see how that goes and how it affects
RequestAuthorizer's implementation. If we can handle it for a single request, it seems like keeping an internal reference to them all and wrapping that in acancelAllRequests()function later would be a simpler extension.
If you feel comfortable contributing at least part of the code, that would be much appreciated! Feel free to open a PR (even an in-progress one) to discuss details or issues. And hopefully the existing doc comments should give you some direction on the thread-safety stuff around emptying the channel and managing the auth state.
Hello @sharplet ! Thanks for your answer and your insights. So far Superb works well in our code, though we are still in the rewriting process of our network layer. We have discussed cancellation internally and for the moment, we don't really handle it, and we will see later if this is something that we might have to implement.
Also, I am opening an issue on your project about another topic
With the improvements to the concurrency model in #39, I'm ready to tackle this. I'm currently working on the ability to cancel a single request, and should hopefully have a PR soon.