Hi Laurent,

On Aug 5, 11:07 am, Laurent PETIT <laurent.pe...@gmail.com> wrote:

> Looks complex.

Hmm.. Maybe we can save the agent and use an atom? (For some reason, I
thought, it wouldn't work with an atom...)

(def *parser* (atom nil))

(defn schedule-parse
  []
  (reset! *parser* (delay (parse-stuff))))

(defn trigger-parse
  ([] (trigger-parse 0))
  ([delay-in-millis]
   (future
     (when (pos? delay-in-millis)
       (Thread/sleep delay-in-millis))
     @@*parser*)))

> One think I forgot to mention is that by making the datastructure implement
> the future API, I *desire* the ability to cancel the future while it's still
> sleeping : so that when the user types fast, intemediate values are not
> computed at all.

Well. You can. If you cancel the trigger-parse future while it's
sleeping, the parse run will not be triggered. You can even put more
logic into schedule-parse and only update the delay in the atom if
really necessary.

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