This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-02-02
Channels
- # admin-announcements (33)
- # announcements (2)
- # beginners (75)
- # boot (340)
- # braid-chat (6)
- # cider (30)
- # cljsrn (44)
- # clojars (19)
- # clojure (169)
- # clojure-austin (12)
- # clojure-czech (1)
- # clojure-japan (6)
- # clojure-miami (1)
- # clojure-poland (7)
- # clojure-russia (83)
- # clojurebridge (4)
- # clojurescript (166)
- # community-development (55)
- # component (2)
- # core-async (39)
- # core-matrix (3)
- # cursive (32)
- # data-science (3)
- # datavis (3)
- # datomic (58)
- # dirac (28)
- # emacs (4)
- # events (7)
- # hoplon (254)
- # immutant (29)
- # jobs (2)
- # jobs-discuss (4)
- # ldnclj (35)
- # lein-figwheel (3)
- # mount (202)
- # off-topic (9)
- # om (123)
- # onyx (22)
- # parinfer (112)
- # proton (11)
- # re-frame (6)
- # reagent (43)
- # ring (3)
- # spacemacs (2)
I'm using a library that exposes a websocket connection to me as a manifold/stream. I can connect this to a core.async channel with manifold/stream.->source without a problem. However, if the websocket closes its connection, I'd like to reconnect the stream to my async channel. Manifold provides manifold/on-closed which I can use to register a callback to execute when the stream closes, but I'm having trouble figuring out how to set things up so that anytime my manifold/stream closes, I can get a new one connected back to my core.async channel. Can anyone help point me in the right direction?
hey @gabehollombe sounds like the callback will need to be a closure, closing over the core.async channel you want to reconnect to. and it will need to be able to retrieve a new websocket connection. if you can share some code folks can probably help more.
Yeah, let me try and get a simple example together in a gist.
Here’s an example re-stating my question in clj form as a gist: https://gist.github.com/gabehollombe/b195e5c725784ee1bb54
@jonahbenton: I understand creating closures. My problem is that my brain doesn’t understand how to create a disconnect-handler function that can reference itself again when the new stream closes. I hope this makes sense
Thanks a ton, @jonahbenton — I’ll give this a shot tonight
it makes perfect sense to me, too
Thank you @jonahbenton for that implementation using a lazy sequence.
@jonahbenton: Here’s a slight re-gist using an atom so I can poke at the reconnected socket after it gets re-created. Look OK to you? https://gist.github.com/gabehollombe/1850cd9bc985d7dcb313
hey @gabehollombe: hmm, does that gist work? the use of disconnect-handler in the on-close should fail, no?
it will be transformed into a proper response with :status, :header keywords etc right?
i’ve tried to “graduate” from just handling the html string and letting the macro work its dark magic but what i get instead is a downloaded file with the html when i try to visit the route
I know almost nothing about compojure but the sample app I did has the HTML wraped in (html5 ...) from hiccup.page and it renders fine.
Sorry, it's not an HTML string. It's a hiccup list of stuff.
so here’s a fun question, is there an easy way to pass in and use command args in a clojure app?
Mostly I see people pass in a map string "{:product-id 12345}"
Then you can turn that into a clojure map in your -main function.
@jeff.engebretsen: another newbie Q related to that
No, you'd have to pass the argument map into them.
you can set the map in some global atom.
Why not just pass it as an argument?
or just a def but that would be less idiomatic.
you could also pass your arguments as java properties: -Dproduct.id=1234
, then get them with environ (env :product-id)
Here's an example using atoms. You could put the whole thing into an atom or break out the arguments. https://clojuredocs.org/clojure.core/atom#example-542692cec026201cdc326db7
If the arguments are defined already (def product-id 0)
you can use binding (binding [product-id (:product-id arg-map)] (fn-that-uses-product-id))
That'll shadow the global var until you exit the binding form.
maybe my question is even easier than it seems, i just don’t know how to refer to those commandline args
Are you talking about in your -main
fn?
http://clojure.org/reference/compilation#_gen_class_examples Is this what you're wanting?
@jeff.engebretsen: i believe so, but it would be nice not just have one giant main function
like pass a map as a cli arg then do a bunch of stuff with that data and have it called from main or something
im basically wanting to use clojure in place of shell script where a shell script is a bit of a pain. shell scripting argument handling is a cinch but for the problem i’m solving i’d love to do the work with clojure
From your main function, you have access to the args. So you can grab what you need from the args and then call other functions using them.
@solicode: so i can call other functions i define within main and pass args to them since they’d have access within main
(defn -main [& args]
(let [[first-arg second-arg] args]
(my-function first-arg second-arg)))
You can define the functions elsewhere, like a different namespace even and call them from -main
if you pass in a command line arg it show up as a string, is there a way to “deserialize” that
You can use read-string
, but I would use the edn version:
https://clojuredocs.org/clojure.edn/read-string