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.

Sincerely
Meikel

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