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)
|
||||
: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
|
||||
(pedestal/routing-interceptor
|
||||
(http/router
|
||||
|
|
@ -19,19 +29,11 @@
|
|||
["/sync"
|
||||
{:interceptors [[interceptor :sync]]
|
||||
:get {:interceptors [[interceptor :get]]
|
||||
:handler (fn [_]
|
||||
(println "handler")
|
||||
{:status 200,
|
||||
:body "pong"})}}]
|
||||
:handler handler}}]
|
||||
|
||||
["/async"
|
||||
{:interceptors [[interceptor :async]]
|
||||
:get {:interceptors [[interceptor :get]]
|
||||
:handler (fn [_]
|
||||
(a/go
|
||||
(println "handler")
|
||||
{:status 200,
|
||||
:body "pong"}))}}]]
|
||||
:get {:interceptors [[interceptor :get] async-handler]}}]]
|
||||
{:data {:interceptors [[interceptor :router]]}})
|
||||
(ring/create-default-handler)
|
||||
{:interceptors [[interceptor :top]]}))
|
||||
|
|
|
|||
Loading…
Reference in a new issue