/gist:03fae5146befe9c24868 Secret
Last active
December 30, 2015 05:09
-
-
Save ztellman/03fae5146befe9c24868 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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