Re: Agents for managing threads

2009-10-13 Thread John Harrop
On Tue, Oct 13, 2009 at 7:24 AM, Robert Stehwien wrote: > John, > > Excellent "library" I'm pulling this into my utilities functions ... with > proper attribution of course and as long as you don't mind. It is just too > useful to me to not keep around. Thanks. Consider any code I post here to

Re: Agents for managing threads

2009-10-13 Thread Robert Stehwien
John, Excellent "library" I'm pulling this into my utilities functions ... with proper attribution of course and as long as you don't mind. It is just too useful to me to not keep around. --Robert On Sat, Oct 10, 2009 at 1:54 AM, John Harrop wrote: > Here is a quickie "library" for abstracti

Re: Agents for managing threads

2009-10-12 Thread John Harrop
Thanks. --~--~-~--~~~---~--~~ 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

Re: Agents for managing threads

2009-10-11 Thread Garth Sheldon-Coulson
Hi All, Thanks for the great replies. John, the self-send-off idea is terrific and hadn't occurred to me. I'll be using a variant of what you proposed. Garth On Sun, Oct 11, 2009 at 10:29 PM, John Harrop wrote: > On Sun, Oct 11, 2009 at 5:28 PM, Raoul Duke wrote: > >> >> will actors actually

Re: Agents for managing threads

2009-10-11 Thread John Harrop
On Sun, Oct 11, 2009 at 5:28 PM, Raoul Duke wrote: > >> will actors actually do the queued function w/in a reasonable > >> timeframe? i don't think there are any guarantees of it so if one is > >> hoping to get really nicely periodic behaviour... just curious because > >> i'd thought of using age

Re: Agents for managing threads

2009-10-11 Thread Raoul Duke
>> will actors actually do the queued function w/in a reasonable >> timeframe? i don't think there are any guarantees of it so if one is >> hoping to get really nicely periodic behaviour... just curious because >> i'd thought of using agents for periodic stuff, too. > > In practice, they seem to.

Re: Agents for managing threads

2009-10-10 Thread John Harrop
On Sat, Oct 10, 2009 at 5:52 PM, Raoul Duke wrote: > > > The actor itself is > > an agent wrapping a vector with the function, period, awake flag, and > > current parameters. > > will actors actually do the queued function w/in a reasonable > timeframe? i don't think there are any guarantees of i

Re: Agents for managing threads

2009-10-10 Thread Raoul Duke
> The actor itself is > an agent wrapping a vector with the function, period, awake flag, and > current parameters. will actors actually do the queued function w/in a reasonable timeframe? i don't think there are any guarantees of it so if one is hoping to get really nicely periodic behaviour...

Re: Agents for managing threads

2009-10-10 Thread John Harrop
Here is a quickie "library" for abstracting this: (defn make-actor [f period-in-ms & initial-state] (agent (into [f period-in-ms false] initial-state))) (defmacro actor "Creates and returns a new, initially-sleeping actor with the specified period, initial parameter values, and code to execute

Re: Agents for managing threads

2009-10-08 Thread John Harrop
On Thu, Oct 8, 2009 at 7:49 PM, John Harrop wrote: > You might be able to do better than that, and dispense entirely with the > separate polling thread. > Confirmed: (def x (agent {:polling false :message "foo"})) (defn poll [m] (when (:polling m) (prn (:message m)) (Thread/sleep 100

Re: Agents for managing threads

2009-10-08 Thread John Harrop
On Thu, Oct 8, 2009 at 1:06 PM, Laurent PETIT wrote: > So I don't think you need this message-queue at all (or maybe I haven't > understood what it is or I'm mislead by its name), send directly your order > to the agent as what you want to change in its state. You might be able to do better than

Re: Agents for managing threads

2009-10-08 Thread Laurent PETIT
I'm not an expert on asynchronicity with clojure, but I'll benefit from the fact i'll be the first to answer :-) But please take this with a grain of salt. As I see agents, in their generality, they are "a generic way to handle a state asynchronously (commands from multiple non organized sources -

Agents for managing threads

2009-10-08 Thread Garth Sheldon-Coulson
Hi All, This is a question about whether I can use agents or some other Clojure concurrency feature to manage a multithreaded process elegantly and extensibly. The following is a thought I had for how to do it, but I would appreciate additional suggestions. I have an application that needs to pol