https://github.com/james-henderson/chord
Chord is a library for making WebSockets look like simple core.async
channels in Clojure (using http-kit) and ClojureScript.
Basic usage:
Leiningen:
[jarohen/chord "0.2.1"]
ClojureScript:
(:require [chord.client :refer [ws-ch]]
[cljs.core.async :refer [<! >! put! close!]])(:require-macros
[cljs.core.async.macros :refer [go]])
(go
(let [ws (<! (ws-ch "ws://localhost:3000/ws"))]
(>! ws "Hello server!")
(loop []
(when-let [{:keys [message]} (<! ws)]
(js/console.log "Got message from server:" message)
(recur)))))
Clojure (a wrapper around http-kit's 'with-channel'):
(:require [chord.http-kit :refer [with-channel]]
[clojure.core.async :refer [<! >! put! close! go]])
(defn your-handler [req]
(with-channel req ws-ch
(go
(let [{:keys [message]} (<! ws-ch)]
(println "Message received from client:" message)
(>! ws-ch "Hello client from server!")
(close! ws-ch)))))
There's more documentation and a few code examples on the Github page, and
a full example project in the repo.
Feedback is *always very welcome* - either here, through Github in the
usual way or (if it fits into 140 chars!) Twitter.
Version 0.2.1 brings the ability to specify custom buffered channels -
thanks to Timo Sulg for the PR!
James (@jarohen)
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.