Re: How to do aynchrounous producer/consumer

2012-06-17 Thread Warren Lynn

Thank you all for the suggestions. I decided to use Java as lamina seems an 
overkill for me and I may lose some control over things I want to have. I 
was wishing for a pure Clojure solution, but a wrapping layer over the Java 
works fine.


On Sunday, June 17, 2012 4:43:17 AM UTC-4, Jeff Rose wrote:
>
> Java has queues that will do just what you want, as well as thread pools 
> to process the jobs.  It's reasonable and idiomatic to use this stuff from 
> Clojure.  
>
>
> http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html
>
> -Jeff
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

How to do aynchrounous producer/consumer

2012-06-17 Thread Jeff Rose
Java has queues that will do just what you want, as well as thread pools to 
process the jobs.  It's reasonable and idiomatic to use this stuff from 
Clojure.  

http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html

-Jeff

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


How to do aynchrounous producer/consumer

2012-06-17 Thread Jeff Rose
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: How to do aynchrounous producer/consumer

2012-06-16 Thread Zhitong He
try lamina? https://github.com/ztellman/lamina/

On Sat, Jun 16, 2012 at 9:44 AM, Warren Lynn  wrote:
>
> What I want to do is something I probably have done dozens of times in C++:
> two threads, one thread putting items in a queue, another taking it out
> (FIFO). How to do it in Clojure? I am at a loss. I thought about a few
> options:
>
> 1. "watches", but it cannot change the queue itself (can only watch). plus,
> I am not sure watch function will run in another thread
> 2. "agent", but how to notify the consumer thread when there is new item?
> How to block the consumer thread when there is no items in the queue?
> 3.  Ping-pong promises: so the producer delivers a promise to the consumer,
> and the consumer immediately deliver another promise to the producer to
> acknowledge the receipt so the producer can move on. But that will prevent
> the producer to put the next item into the queue before the consumer finish
> its processing, so not exactly concurrent.
>
> I cannot believe I am the first one to encounter this. Can anyone suggest
> some idiomatic solution for the above? Thank you.
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



-- 
Zhitong He
Sun Yat-sen University

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: How to do aynchrounous producer/consumer

2012-06-16 Thread Warren Lynn


On Saturday, June 16, 2012 12:47:03 AM UTC-4, Alan Malloy wrote:
>
> (map consume (seque (produce-lazily)))
>
>
Thank you! This is not exactly what I want (my input data is pushed from an 
external Java framework), but I was not aware there is a "seque" function, 
which might be useful for my other use cases.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: How to do aynchrounous producer/consumer

2012-06-15 Thread Alan Malloy
(map consume (seque (produce-lazily)))

On Friday, June 15, 2012 6:44:39 PM UTC-7, Warren Lynn wrote:
>
>
> What I want to do is something I probably have done dozens of times in 
> C++: two threads, one thread putting items in a queue, another taking it 
> out (FIFO). How to do it in Clojure? I am at a loss. I thought about a few 
> options:
>
> 1. "watches", but it cannot change the queue itself (can only watch). 
> plus, I am not sure watch function will run in another thread
> 2. "agent", but how to notify the consumer thread when there is new item? 
> How to block the consumer thread when there is no items in the queue?
> 3.  Ping-pong promises: so the producer delivers a promise to the 
> consumer, and the consumer immediately deliver another promise to the 
> producer to acknowledge the receipt so the producer can move on. But that 
> will prevent the producer to put the next item into the queue before the 
> consumer finish its processing, so not exactly concurrent.
>
> I cannot believe I am the first one to encounter this. Can anyone suggest 
> some idiomatic solution for the above? Thank you.
>
>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

How to do aynchrounous producer/consumer

2012-06-15 Thread Warren Lynn

What I want to do is something I probably have done dozens of times in C++: 
two threads, one thread putting items in a queue, another taking it out 
(FIFO). How to do it in Clojure? I am at a loss. I thought about a few 
options:

1. "watches", but it cannot change the queue itself (can only watch). plus, 
I am not sure watch function will run in another thread
2. "agent", but how to notify the consumer thread when there is new item? 
How to block the consumer thread when there is no items in the queue?
3.  Ping-pong promises: so the producer delivers a promise to the consumer, 
and the consumer immediately deliver another promise to the producer to 
acknowledge the receipt so the producer can move on. But that will prevent 
the producer to put the next item into the queue before the consumer finish 
its processing, so not exactly concurrent.

I cannot believe I am the first one to encounter this. Can anyone suggest 
some idiomatic solution for the above? Thank you.



-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en