This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-20
Channels
- # bangalore-clj (3)
- # beginners (30)
- # boot (117)
- # braid-chat (6)
- # carry (9)
- # cider (6)
- # clara (11)
- # cljs-dev (28)
- # cljsrn (12)
- # clojars (2)
- # clojure (114)
- # clojure-austin (2)
- # clojure-dev (1)
- # clojure-dusseldorf (1)
- # clojure-greece (47)
- # clojure-italy (5)
- # clojure-russia (79)
- # clojure-spec (121)
- # clojure-uk (133)
- # clojurescript (92)
- # community-development (67)
- # copenhagen-clojurians (1)
- # core-async (25)
- # cursive (67)
- # datascript (1)
- # datomic (34)
- # devcards (24)
- # emacs (8)
- # funcool (71)
- # juxt (1)
- # keechma (2)
- # lein-figwheel (6)
- # luminus (8)
- # mount (17)
- # om (135)
- # om-next (13)
- # onyx (147)
- # pedestal (11)
- # planck (7)
- # re-frame (42)
- # reagent (86)
- # rum (11)
- # specter (6)
- # testing (6)
- # untangled (1)
- # vim (6)
- # yada (24)
Ok I'm... having an issue with websockets, I'm using guiznado, which is just about the only lib I've found with a proper example of a websocket client in clojure and not in clojurescript... ๐ Does anyone have experience with doing this with guiznado, or maybe an alternate ws server lib I could use with some examples?
@eslachance: Have you looked at sente? https://github.com/ptaoussanis/sente
I did... maybe it's my noobness, but I'm seeing the websocket client as being CLJS, not CLJ...
so unless I can just use it as-is in CLJ... I dunno
Even then I don't even see any connect methods
Oh might be, I didn't think that far :)
That's my issue... most people don't feel the need to create a websocket client on the server-side...
Hmm..... aleph
maybe.... https://github.com/ztellman/aleph/blob/master/examples/src/aleph/examples/websocket.clj
luckyevie: Iโve used guiznado before, a while ago but it did work alright for me, wait I think I used it in an opensource project, let me see if I can get you a link ...
luckyevie: I am using it here to connect to the slack RTM websocket: https://github.com/verma/clj-slackbot/blob/master/src/clj_slackbot/comms/slack_rtm.clj#L4
Thanks Verma! You (I think?) already sent this to me over a week ago and admitedly it's the basis of pretty much all my knowledge of websockets in Clojure ^_^
(Would have gotten to this issue sooner but discord and node keep pulling me back with urgent or interesting issues)
I do have a lot more complexity to my program though - I have around 2 pages of flowchart data for opcodes coming in an out of the Discord API. It's just a question of using the proper case
though. I do have a friend helping me... or rather, who will after his WoW dailies (ahhhh, games. The eternal method of pushing back deadlines)
the only think I can probably suggest is that abstract the websocket out early into something clojure-esqe (e.g. core.async) and just make it sufficiently error resilient.
I'm actually using core.async, I fell in love with it immediately.
So I at least got that!
Uhm... Let's say I define a function like the following, and I want to have a way to... stop the go-loop
on command. How would I go about doing this?
(defn ping-pong [out-pipe delay]
(let [counter (atom 0)
next-id #(swap! counter inc)]
(go-loop []
(<! (timeout delay))
(println "Sending a ping request")
(>! out-pipe {:op 1 :d (next-id)} )
(recur))))
(actually I'd also need to reset the Atom to 0)
(btw I did figure out my websockets issue, I wasn't defining any arguments in the :on-error
function but the error message was somewhat vague about it)
There's a trick for that using an extra channel to signal "stop", and then "select" on multiple channels
(if (not kill-chan)
(let [kill-chan (async/chan)]
(async/go-loop []
(let [[event ch] (async/alts! [input-chan kill-chan])]
(if (= ch kill-chan)
(async/close! kill-chan)
(do
(process-event! event events)
(recur)))))
(assoc this :kill-chan kill-chan))
this)
I use this in a component, you'll need to tweak it slightly for your use case. To kill the loop:
(async/>!! kill-chan :kill)
yup, that's the one. alts!
will read from whichever channel has something to give it, and it returns the thing that came of the channel+the channel itself
Awesome! Thank you