Cedric Greevey <cgree...@gmail.com> writes:

Hi Cedric,

>> Do I see it correctly that you need a way (1) to have objects
>> implementing Job which (2) can be instantiated with a zero-args
>> constructor and (3) whose execute behavior is customizable by
>> providing an arbitrary function f on the JobExecutionContext?
>>
>> If so, I don't see a too good way.  deftype would be usable if the
>> function f would be specified as a field of the type, but then it has
>> no zero-args constructor...
>
> (let [f (atom (fn [_] (throw (IllegalStateException.))))]
>   (defn set-job-fn! [x]
>     (reset! f x))
>   (deftype Job []
>     Job
>     (execute [ctx]
>       (@f ctx))))
>
> Elaborate as you see fit with e.g. a with-job-fn macro or whatever
> inside the let.

I suspect that won't work for the OP, because every Job instance's
execution will evaluate the function that is the atom f's value at that
time.  I have the impression that he wants both Jobs that bark and Jobs
that meow at the same time, and what they do should be specified at
definition time.  With your approach, you need to call set-job-fn!
somehow after the JobBuilder instantiated a Job and before it is
executed by the framework, which might be out of the OP's control.

Bye,
Tassilo

-- 
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

Reply via email to