Discussion:
Deferred are deref'ed by compojure/routes. How to get around this?
Martin Raison
2015-05-15 05:20:38 UTC
Permalink
Aleph's README says handlers may return a deferred to represent an eventual
response.
In the HTTP examples
<http://ideolalia.com/aleph/literate.html#aleph.examples.http>, it also
uses compojure/routes to define the routes.

However, before returning the response to the middleware, compojure
actually "renders" the result. This means that, since deferred implements
IDeref, compojure calls deref
<https://github.com/weavejester/compojure/blob/639fffd3f8b77153644d0c9b87bca5af56be0cb0/src/compojure/response.clj#L36>
on the deferred before passing the response back to the middleware. Isn't
this bad? Does anyone have a good solution to prevent compojure from
deref'ing the result? (both my handler and my middleware do asynchronous
operations, so it seems suboptimal to have a deref in the middle of the
chain)
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Robert Zabel
2015-10-06 08:15:58 UTC
Permalink
Hi,
i think you could do something like this:

(extend-type Deferred
Renderable
(render [this req]
(d/chain this #(render % req))))
Post by Martin Raison
Aleph's README says handlers may return a deferred to represent an
eventual response.
In the HTTP examples
<http://ideolalia.com/aleph/literate.html#aleph.examples.http>, it also
uses compojure/routes to define the routes.
However, before returning the response to the middleware, compojure
actually "renders" the result. This means that, since deferred implements
IDeref, compojure calls deref
<https://github.com/weavejester/compojure/blob/639fffd3f8b77153644d0c9b87bca5af56be0cb0/src/compojure/response.clj#L36>
on the deferred before passing the response back to the middleware. Isn't
this bad? Does anyone have a good solution to prevent compojure from
deref'ing the result? (both my handler and my middleware do asynchronous
operations, so it seems suboptimal to have a deref in the middle of the
chain)
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Zach Tellman
2015-10-06 18:50:44 UTC
Permalink
What version of Compojure are you using? I had thought that in the latest,
the values passed through untouched.
Post by Robert Zabel
Hi,
(extend-type Deferred
Renderable
(render [this req]
(d/chain this #(render % req))))
Post by Martin Raison
Aleph's README says handlers may return a deferred to represent an
eventual response.
In the HTTP examples
<http://ideolalia.com/aleph/literate.html#aleph.examples.http>, it also
uses compojure/routes to define the routes.
However, before returning the response to the middleware, compojure
actually "renders" the result. This means that, since deferred implements
IDeref, compojure calls deref
<https://github.com/weavejester/compojure/blob/639fffd3f8b77153644d0c9b87bca5af56be0cb0/src/compojure/response.clj#L36>
on the deferred before passing the response back to the middleware. Isn't
this bad? Does anyone have a good solution to prevent compojure from
deref'ing the result? (both my handler and my middleware do asynchronous
operations, so it seems suboptimal to have a deref in the middle of the
chain)
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Robert Zabel
2015-10-07 17:13:11 UTC
Permalink
I checked out the latest version on git, they really deref.
Post by Zach Tellman
What version of Compojure are you using? I had thought that in the
latest, the values passed through untouched.
Post by Robert Zabel
Hi,
(extend-type Deferred
Renderable
(render [this req]
(d/chain this #(render % req))))
Post by Martin Raison
Aleph's README says handlers may return a deferred to represent an
eventual response.
In the HTTP examples
<http://ideolalia.com/aleph/literate.html#aleph.examples.http>, it also
uses compojure/routes to define the routes.
However, before returning the response to the middleware, compojure
actually "renders" the result. This means that, since deferred implements
IDeref, compojure calls deref
<https://github.com/weavejester/compojure/blob/639fffd3f8b77153644d0c9b87bca5af56be0cb0/src/compojure/response.clj#L36>
on the deferred before passing the response back to the middleware. Isn't
this bad? Does anyone have a good solution to prevent compojure from
deref'ing the result? (both my handler and my middleware do asynchronous
operations, so it seems suboptimal to have a deref in the middle of the
chain)
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...