Skip to content

Commit 540b169

Browse files
committed
backport src/compojure/api/async.clj
1 parent 5dcc20a commit 540b169

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/compojure/api/async.clj

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(ns compojure.api.async
2+
(:require [compojure.response :as response]
3+
[compojure.api.common :as common]
4+
compojure.api.routes))
5+
6+
(common/when-ns 'manifold.deferred
7+
;; Compojure is smart enough to get the success value out of deferred by
8+
;; itself, but we want to catch the exceptions as well.
9+
(extend-protocol compojure.response/Sendable
10+
manifold.deferred.IDeferred
11+
(send* [deferred request respond raise]
12+
(manifold.deferred/on-realized deferred #(response/send % request respond raise) raise))))
13+
14+
(common/when-ns 'clojure.core.async
15+
(extend-protocol compojure.response/Sendable
16+
clojure.core.async.impl.channels.ManyToManyChannel
17+
(send* [channel request respond raise]
18+
(clojure.core.async/go
19+
(let [message (clojure.core.async/<! channel)]
20+
(if (instance? Throwable message)
21+
(raise message)
22+
(response/send message request respond raise)))))))
23+
24+
(extend-protocol compojure.response/Sendable
25+
compojure.api.routes.Route
26+
(send* [this request respond raise]
27+
((.handler this) request #(response/send % request respond raise) raise)))

0 commit comments

Comments
 (0)