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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -