Hi,
the average channel has no queue. Processes freeze until the peer process
arrives. So count doesn't make sense for the typical channel. If you want
to implement a queue, you could create a process which accepts values on
end and distributes to the other. Then you can keep also track of any stats
you like independent of the underlying channel implementation.
(defn queue-process
[input output stats]
(async/go
; Wait for the first input.
(loop [v (async/<! input)
q clojure.lang.PersistentQueue/EMPTY]
(let [[val-to-q ch] (async/alts! [input [output v]])]
(swap! stats update-stats q)
(cond
; Read a value from input.
val-to-q (recur v (conj q val-to-q))
; Input channel is closed. => Empty queue.
(identical? ch input) (do
(doseq [v (cons v q)]
(async/>! output v))
(async/close! output))
; Write happened, and there is more in the queue.
(pos? (count q)) (recur (peek q) (pop q))
; Write happened, and queue is empty. Start over.
:else (recur (async/<! input) q))))))
With something like that, you can implement any queueing strategy (bounded,
priority, etc.) you like with any stats you want to collect without
polluting the general channel interface.
Disclaimer: I haven't used core.async much, yet. So there might be glitches
in the above, but you should get the idea. Also, it might be a bad idea
altogether.
Meikel
--
--
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.