Ring uses blocking I/O by default, because that's often sufficient for most web servers, and is generally easier to reason about. HTTP works best when the response is returned ASAP, which means blocking I/O typically isn't much of a bottleneck.
However, since Ring 1.2, all of the standard middleware has also been available to use asynchronously, in order to support frameworks like Pedestal. So it's certainly possible to use Ring in an async environment, at least with the core Ring libs. Although HTTP Kit doesn't use core.async channels itself, the async protocol used isn't complex. You should be able to hook up core.async/take! to http-kit/send!. Something like: (defn handler [req] (httpkit/with-channel req http-ch (let [resp-ch (async-handler! req)] (httpkit/on-close (fn [_] (a/close! resp-ch))) (a/take! resp-ch (fn [resp] (httpkit/send! http-ch resp) (httpkit/close http-ch)))))) That said, I'd be wary about having HTTP clients wait around on the server. If it's just a few seconds, that seems reasonable, but any longer and you should consider redirecting to a "job" resource instead. - James On 2 September 2014 16:41, Laurens Van Houtven <_...@lvh.cc> wrote: > Hi, > > > I'm writing a pretty simple HTTPS API that, when you make a request to it, > it makes a bunch of requests on your behalf, and eventually reports success > or failure. Because it makes many requests with a bunch of interaction > between them, I'd really like to use core.async. Internally (that is, until > it hit the HTTP server API), it's a channel with a bunch of maps on it that > eventually closes when it's done. I can write the code to turn this > bunch-of-maps into a suitable response map, but the hard part seems to be > getting HTTP servers to accept a channel instead of a synchronous response. > > I started with ring and a bunch of middleware, but ring seems to really > want me to return a request map synchronously. I guess the API that I'd > ideally want is something just like a ring handler (and that works with > ring middleware), but instead lets me return a (core.async) channel. That > channel would probably just return a single response map and close. > > I was already using http-kit for the asynchronous client, so I started > with using it as the server as well. Unfortunately it does not appear to > support the API above. The async server API is this long-polling/websockety > thing that lets me pipe in some data (which is ignored by middleware), but > I do really want simple HTTP(S) request/response pairs. Just lots of them > :-) > > Doing take!! off that channel with the request-map might work, but > probably isn't the best idea in terms of concurrency. > > > thanks in advance for your suggestions, > lvh > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.