Hi all,
I ran into a core.async behaviour that confused me a bit the other day. In
some of our systems, we need to fire different timeouts, perform actions
and schedule a new timeout. The problem is, that if the timeouts are of the
same number of ms, we can't distinguish them, and therefore not keep track
of and remove them from a set (at least not easily).
That sounds a bit fuzzy. Hopefully this spike will make it clearer what I'm
trying to say:
(require '[clojure.core.async :refer [chan timeout alts!! alts!]])
(= (chan) (chan))
;; false
(= (timeout 1) (timeout 2))
;; false
(= (timeout 1) (timeout 1))
;; true
(do (loop [ch->v (into {} (for [v [1 2 3]] [(timeout 1000) v]))]
(when-let [chs (keys ch->v)]
(let [[_ ch] (alts!! chs)]
(println (ch->v ch))
(recur (dissoc ch->v ch)))))
(println "done"))
;; only fires "3", the last channel in the map
The intended behaviour of the last loop is to print 1, 2 and 3 (not
necessarily in that order). However, the ch->v map will only contain one
key, as timeouts with the same duration are considered the same value. In
the real example, a new timeout with the same value should be scheduled
again, by being put in the map.
So, my questions are:
- Is this intended behaviour?
- Is there a different pattern for achieving the scheduling behaviour I'm
looking for?
Thanks for your help,
Thomas
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.