Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to cancel execution when client is disconnected? #381

Open
kachayev opened this issue Apr 20, 2018 · 0 comments
Open

How to cancel execution when client is disconnected? #381

kachayev opened this issue Apr 20, 2018 · 0 comments

Comments

@kachayev
Copy link
Collaborator

kachayev commented Apr 20, 2018

Right now there's no obvious way to cancel request processing as we do not have access to the information about connection status in the handler. With this change I can do something like (pseudo-code):

(defn handler [req]
  (let [s' (manifold.stream/stream)
        d' (process-request req)]
     (manifold.stream/on-close s' (fn [] (manifold.deferred/error! d' ::closed)))
     (manifold.deferred/chain'
        d'
        (fn [r]
           (manifold.stream/put! s' r)
           (manifold.stream/close! s')))
     {:status 200
      :body s'}))

But this would change semantic in many cases as it forces me to use chunked transfer and it sends status/headers right away. I think the good approach to tackle this would be to inject into the request map something like :aleph/termination-future that I could use to setup a listener when necessary. Or even provide such functionality as a configurable "cancellation" behavior. @ztellman what do you think?

P.S. I'm not also sure about using manifold.deferred/error!, but as far as I see there's not "cancel" state in manifold's deferred, so setting error state seems the most reasonable approach here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant