mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 08:51:12 +00:00
fix async code
This commit is contained in:
parent
9ca63b545b
commit
86fb0f72d0
1 changed files with 12 additions and 10 deletions
|
|
@ -9,6 +9,16 @@
|
||||||
{:enter (fn [ctx] (println ">>" x) ctx)
|
{:enter (fn [ctx] (println ">>" x) ctx)
|
||||||
:leave (fn [ctx] (println "<<" x) ctx)})
|
:leave (fn [ctx] (println "<<" x) ctx)})
|
||||||
|
|
||||||
|
(defn handler [_]
|
||||||
|
(println "handler")
|
||||||
|
{:status 200,
|
||||||
|
:body "pong"})
|
||||||
|
|
||||||
|
(def async-handler
|
||||||
|
{:enter (fn [{:keys [request] :as ctx}]
|
||||||
|
(a/go
|
||||||
|
(assoc ctx :response (handler request))))})
|
||||||
|
|
||||||
(def routing-interceptor
|
(def routing-interceptor
|
||||||
(pedestal/routing-interceptor
|
(pedestal/routing-interceptor
|
||||||
(http/router
|
(http/router
|
||||||
|
|
@ -19,19 +29,11 @@
|
||||||
["/sync"
|
["/sync"
|
||||||
{:interceptors [[interceptor :sync]]
|
{:interceptors [[interceptor :sync]]
|
||||||
:get {:interceptors [[interceptor :get]]
|
:get {:interceptors [[interceptor :get]]
|
||||||
:handler (fn [_]
|
:handler handler}}]
|
||||||
(println "handler")
|
|
||||||
{:status 200,
|
|
||||||
:body "pong"})}}]
|
|
||||||
|
|
||||||
["/async"
|
["/async"
|
||||||
{:interceptors [[interceptor :async]]
|
{:interceptors [[interceptor :async]]
|
||||||
:get {:interceptors [[interceptor :get]]
|
:get {:interceptors [[interceptor :get] async-handler]}}]]
|
||||||
:handler (fn [_]
|
|
||||||
(a/go
|
|
||||||
(println "handler")
|
|
||||||
{:status 200,
|
|
||||||
:body "pong"}))}}]]
|
|
||||||
{:data {:interceptors [[interceptor :router]]}})
|
{:data {:interceptors [[interceptor :router]]}})
|
||||||
(ring/create-default-handler)
|
(ring/create-default-handler)
|
||||||
{:interceptors [[interceptor :top]]}))
|
{:interceptors [[interceptor :top]]}))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue