2010/8/5 Meikel Brandmeyer <m...@kotka.de>

> Hi,
>
> On Aug 5, 2:14 pm, Laurent PETIT <laurent.pe...@gmail.com> wrote:
>
> > (ns delay.util)
> >
> > (defprotocol Cancellable (isCancelled [this]) (cancel [this]))
> >
> > (defn timed-delay [pause fun]
> >   (let [d (delay (fun))
> >         f (future (Thread/sleep pause) @d)]
> >     (reify
> >       clojure.lang.IDeref
> >         (deref [_] @d)
> >       delay.util.Cancellable
> >         (isCancelled [_] (future-cancelled? f))
> >         (cancel [_] (future-cancel f)))))
> >
> > What about this ?
>
> This looks ok, I think. At least better than "hijacking" the future.
>
> However, I'm still the opinion, that you mix up concerns here.
> "Cancellable" somehow implies that it stops whatever the thing is
> doing. But it has no influence on the deref. To me this would be
> surprising.
>
> For me the whole future thing is a side-effect which is not relevant
> to the consumer of the parsed code. It is a convenience which can be
> tracked separately from the actual delay.
>

Yes, maybe I'm putting too much ... will need to think about it again

But I don't understand your usage of the expression "side-effect". e.g. the
instance given will play well in any situation. Even if you call cancel on
it, this will not prevent following calls to deref to succeed. So holders of
a reference to it can use it without knowing at all that the instance also
implements the Cancellable interface. Maybe it's the names that must be
adjusted.

After all I was wrong, it's not a delayed delay I've written.
How to rename things ?

timed-delay ->  ?
delay.util.Cancellable ->  ?
isCancelled -> ?
cancel -> ?

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