Created
May 5, 2014 21:12
-
-
Save valichek/ba510de9ff2cf3d0c502 to your computer and use it in GitHub Desktop.
Strange behaviour of merge and into with map where keys are instances of AsyncChannel from http-kit
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 clj-test-server.core | |
(:use org.httpkit.server)) | |
; https://github.com/http-kit/http-kit/blob/master/src/java/org/httpkit/server/AsyncChannel.java | |
(def clients (atom nil)) | |
(defn handler [] | |
(future (let | |
[merged (merge {} @clients)] | |
(println merged)) ; => #<ManyToManyChannel clojure.core.async.impl.channels.ManyToManyChannel@5d9c832a>, but expect to get copy of @clients | |
#_(let | |
[into-map (into {} @clients)] ; here I get exception <IllegalArgumentException java.lang.IllegalArgumentException: No implementation of method: :take! of protocol: #'clojure.core.async.impl.protocols/ReadPort found for class: nil | |
(println into-map)))) | |
(defn ws | |
[req] | |
(with-channel req con | |
(swap! clients assoc con true) | |
(println con " connected") | |
(on-receive con (fn [data] | |
(handler))) | |
(on-close con (fn [status] | |
(swap! clients dissoc con) | |
(println con " disconnected. status: " status))))) | |
(defn -main [] | |
(let [port 10001] | |
(run-server ws {:port port :join? false})) | |
(println "ok!")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment