Is there a way to be notified when a clojure future finishes? -
is there way set watch on future triggers callback when done?
something this?
> (def (future (thread/sleep 1000) "hello world!") > (when-done (println @a)) ...waits 1sec... ;; => "hello world"
you can start task watches future , runs function. in case i'll use future. wraps nicely when-done function:
user=> (defn when-done [future-to-watch function-to-call] (future (function-to-call @future-to-watch))) user=> (def meaning-of-the-universe (let [f (future (thread/sleep 10000) 42)] (when-done f #(println "future available , answer is:" %)) f)) #'user/meaning-of-the-universe ... waiting ... user=> future available , answer is: 42 user=> @meaning-of-the-universe 42
Comments
Post a Comment