Skip to content

Instantly share code, notes, and snippets.

@ztellman
Forked from aconbere/gist:1d709e8746cc81eb519c
Last active December 30, 2015 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ztellman/03fae5146befe9c24868 to your computer and use it in GitHub Desktop.
Save ztellman/03fae5146befe9c24868 to your computer and use it in GitHub Desktop.
(ns ac.core
(:require [clojure.core.async :as async :refer [<! >! >!! <!! chan go go-loop]])
(:use [lamina core] [aleph tcp] [gloss core]))
(defn make-handler
[async-in async-out]
(fn [_ch _]
(go-loop
[msg (<! async-out)]
(enqueue _ch (<!! msg))
(recur (<! async-out)))
(future
(doseq [m (channel->lazy-seq ch)]
(>!! async-in msg)))))
(defn start
[opts]
(let [in (chan)
out (chan)]
(start-tcp-server (make-handler in out) opts)
[in out]))
(defn -main
[]
(let [opts {:port 1234 :frame (string :utf-8 :delimiters ["\r\n"])}
[in out] (start opts)]
(go-loop [msg (go (<! in))]
(println (<!! msg))
(recur (go (<! in))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment