This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-02-01
Channels
- # aatree (1)
- # admin-announcements (11)
- # beginners (77)
- # boot (73)
- # braid-chat (29)
- # cbus (3)
- # clara (3)
- # cljs-dev (16)
- # cljsjs (2)
- # cljsrn (68)
- # clojure (149)
- # clojure-austin (1)
- # clojure-czech (2)
- # clojure-miami (8)
- # clojure-poland (28)
- # clojure-russia (165)
- # clojure-ukraine (1)
- # clojurebridge (3)
- # clojurescript (64)
- # community-development (1)
- # core-async (27)
- # core-matrix (2)
- # cursive (38)
- # data-science (2)
- # datavis (4)
- # datomic (3)
- # dirac (78)
- # emacs (10)
- # events (1)
- # funcool (6)
- # hoplon (25)
- # immutant (2)
- # jobs (3)
- # ldnclj (34)
- # luminus (4)
- # mount (23)
- # off-topic (26)
- # om (121)
- # onyx (320)
- # other-lisps (1)
- # proton (13)
- # re-frame (33)
- # yada (3)
@jgdavey: thanks - it has some idiomatic code that I can learn from. I think the next trick is to do the windowing. I am thinking that I can have another channel that sends a message every N seconds that can be used to trigger the formation of a new window...
BTW I’m generally interested in the kind of event windowing that Flink has but the Flink API is pretty awful for Clojure users and I figure that as @alandipert always says ‘LISP can do it’
Hi, I'm pretty new to core-async
, and super stuck at a problem. I have two channels (`point-chan` & print-chan
). The values coming from them two is what I send into my render!
function.
I want to render every time there is an update to either channel. For instance, when point-chan
has an update, I want to call (render! scene (<! point-chan) last-value-from-print-chan)
, but when print-chan
gets an update, I want to (render! scene last-value-from-point-chan (<! print-chan))
.
My question is can you even 'join' two core-async
channels like that? Do I need to keep state in a ref
or something?
Thankful for any input, as my output is blocked 😉
you can use a loop around alts!! or alts! to wait for either channel to produce a value, then do a channel-specific response
Thank you @alexmiller for replying. I not really getting your train of thought here. With alts!
I can get the value of either channel as soon as they get a value. But I cannot 1: distinguish what channel got a message or 2: 'remember' the 'other' channels last value.
The channels will not update at the same time, but I need the value from both of then to pass into render!
.
How can you feed the output of alts! into a loop like that?
alts! will return a vector of [value channel], so you can tell which channel is responding
but you're saying that you need the last value of both channels to pass to render, right?
Exactly
Ah, you can of course do (= ch print-chan)
(where ch comes from alts!)
in that case, I would use a loop/recur, where you retain the last value of both on each pass through the loop
`(loop [last-point nil, last-print nil] (render! scene last-point last-print) (let [[v ch] (alts! [point-chan print-chan]] (if (= ch point-chan) (recur v last-print) (recur last-point v))))
(loop [last-point nil, last-print nil] (render! scene last-point last-print) (let [[v ch] (alts! [point-chan print-chan]] (if (= ch point-chan) (recur v last-print) (recur last-point v))))
gah, kill me now
Oh I think I get it! Wow that if freaking awesome
Even simple
(loop [last-point nil, last-print nil]
(render! scene last-point last-print)
(let [[v ch] (alts! [point-chan print-chan]]
(if (= ch point-chan) (recur v last-print) (recur last-point v))))
alt! actually lets you build the if into this more cleanly
Man thank you! That is seriously cool
but I have a harder time remembering the syntax :)
Thanks a lot. Writing for-loops all day and doing clojure at home after work, and got stuck on this one. Thank you for pointing me in the right way . Will be a good night of hacking
Gonna try getting it with alt!
then as an exercise
alt is basically alts + conditionally choosing what to do based on which channel fires
so seems a good match here, but the syntax is a little tricky
Seems like cond
for channels
well, really cond for alt