Skip to content

Instantly share code, notes, and snippets.

@valichek
Created May 5, 2014 21:12
Show Gist options
  • Save valichek/ba510de9ff2cf3d0c502 to your computer and use it in GitHub Desktop.
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
(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