I want to build a producer-consumer program in clojure. The requirement is the consumer can drag items from the queue while the producer is putting messages into the queue, if using java I will use ConcurrentLinkedQueue
, but I'm not very sure how to do it in clojure using the immutable collections, please help.
Asked
Active
Viewed 1,021 times
3

James.Xu
- 8,249
- 5
- 25
- 36
-
Do you know about [clojure.lang.PersistentQueue](https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentQueue.java)? – Jeremy Jul 28 '12 at 17:14
-
@JeremyHeiler I'd expect to use pure clojure code like vector, list, ref kind of things to implement this, just dont know if it is possible? – James.Xu Jul 28 '12 at 17:17
2 Answers
3
If you just want 1 consumer, just use an agent. If not see see Clojure Producer Consumer or Producer consumer with qualifications

Community
- 1
- 1

DanLebrero
- 8,545
- 1
- 29
- 30
2
I think you could use Clojure's immutable queue inside of an atom, which would give you atomic access to the queue.

Alex Baranosky
- 48,865
- 44
- 102
- 150