Skip to content

Instantly share code, notes, and snippets.

@reiddraper
Created February 12, 2012 20:38
Show Gist options
  • Select an option

  • Save reiddraper/1810761 to your computer and use it in GitHub Desktop.

Select an option

Save reiddraper/1810761 to your computer and use it in GitHub Desktop.
async IO + thread pool
(ns chat.core
(:use lamina.core aleph.tcp gloss.core)
(:gen-class))
(def broadcast-channel (permanent-channel))
(defn chat-handler [ch client-info]
(receive-all ch #(async (let [value (if (not= "sleep" %)
%
(task (do (Thread/sleep 5000) "I slept!")))]
(enqueue broadcast-channel value)
)))
(siphon broadcast-channel ch))
(defn -main [& args]
(start-tcp-server chat-handler {:port 5000 :frame (string :utf-8 :delimiters ["\r\n"])}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment