Skip to content

Commit

Permalink
Update for new async stuffs.
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias committed Jan 27, 2015
1 parent d4ff28d commit 60a2e23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
10 changes: 5 additions & 5 deletions project.clj
Expand Up @@ -4,13 +4,13 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[org.immutant/immutant "2.0.0-beta1"]
[org.immutant/immutant "2.x.incremental.444"]

;; or bring the artifacts in piecemeal:
;; [org.immutant/caching "2.0.0-beta1"]
;; [org.immutant/messaging "2.0.0-beta1"]
;; [org.immutant/scheduling "2.0.0-beta1"]
;; [org.immutant/web "2.0.0-beta1"]
;; [org.immutant/caching "2.x.incremental.444"]
;; [org.immutant/messaging "2.x.incremental.444"]
;; [org.immutant/scheduling "2.x.incremental.444"]
;; [org.immutant/web "2.x.incremental.444"]

[compojure "1.1.8"]
[ring/ring-core "1.3.0"]
Expand Down
19 changes: 10 additions & 9 deletions src/demo/web.clj
@@ -1,6 +1,6 @@
(ns demo.web
(:require [immutant.web :as web]
[immutant.web.websocket :as ws]
[immutant.web.async :as async]
[immutant.web.middleware :as web-middleware]
[compojure.route :as route]
[compojure.core :refer (ANY GET defroutes)]
Expand All @@ -25,25 +25,26 @@

(def websocket-callbacks
"WebSocket callback functions"
{:on-open (fn [channel handshake]
(ws/send! channel "Ready to reverse your messages!"))
{:on-open (fn [channel]
(async/send! channel "Ready to reverse your messages!"))
:on-close (fn [channel {:keys [code reason]}]
(println "close code:" code "reason:" reason))
:on-message (fn [ch m]
(ws/send! ch (apply str (reverse m))))})
(async/send! ch (apply str (reverse m))))})

(defroutes routes
(GET "/" {c :context} (redirect (str c "/index.html")))
(GET "/" {c :context :as request}
(if (:websocket? request)
(async/as-channel request
websocket-callbacks)
(redirect (str c "/index.html"))))
(GET "/counter" [] counter)
(route/resources "/")
(ANY "*" [] echo))

(defn -main [& {:as args}]
(web/run
(-> routes
(web-middleware/wrap-session {:timeout 20})
;; wrap the handler with websocket support
;; websocket requests will go to the callbacks, ring requests to the handler
(ws/wrap-websocket websocket-callbacks))
(web-middleware/wrap-session {:timeout 20}))
(merge {"host" (env :demo-web-host), "port" (env :demo-web-port)}
args)))

0 comments on commit 60a2e23

Please sign in to comment.