Skip to content

Commit 4f654b0

Browse files
kachayevztellman
authored andcommitted
Async Ring handlers wrapper (#442)
* http/wrap-ring-async-handler helper, discussed in #439 * Fix typo in readme
1 parent 5682527 commit 4f654b0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Aleph exposes data from the network as a [Manifold](https://github.com/ztellman/
88

99
### HTTP
1010

11-
Aleph follows the [Ring](https://github.com/ring-clojure) spec fully, and can be a drop-in replacement for any existing Ring-compliant server. However, it also allows for the handler function to return a [Manifold deferred](https://github.com/ztellman/manifold) to represent an eventual response. This feature may not play nicely with Ring middleware which modifies the response, but this can be easily fixed by reimplementing the middleware using Manifold's [let-flow](https://github.com/ztellman/manifold/blob/master/docs/deferred.md#let-flow) operator.
11+
Aleph follows the [Ring](https://github.com/ring-clojure) spec fully, and can be a drop-in replacement for any existing Ring-compliant server. However, it also allows for the handler function to return a [Manifold deferred](https://github.com/ztellman/manifold) to represent an eventual response. This feature may not play nicely with synchronous Ring middleware which modifies the response, but this can be easily fixed by reimplementing the middleware using Manifold's [let-flow](https://github.com/ztellman/manifold/blob/master/docs/deferred.md#let-flow) operator. `aleph.http/wrap-ring-async-handler` helper can be used to covert async 3-arity Ring handler to Aleph-compliant one.
1212

1313
```clj
1414
(require '[aleph.http :as http])

src/aleph/http.clj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,14 @@
388388
rather than a comma-delimited string."
389389
[^aleph.http.core.HeaderMap headers ^String k]
390390
(-> headers ^io.netty.handler.codec.http.HttpHeaders (.headers) (.getAll k)))
391+
392+
(defn wrap-ring-async-handler
393+
"Converts given asynchronous Ring handler to Aleph-compliant handler.
394+
395+
More information about asynchronous Ring handlers and middleware:
396+
https://www.booleanknot.com/blog/2016/07/15/asynchronous-ring.html"
397+
[handler]
398+
(fn [request]
399+
(let [response (d/deferred)]
400+
(handler request #(d/success! response %) #(d/error! response %))
401+
response)))

0 commit comments

Comments
 (0)