Created
August 21, 2013 15:26
-
-
Save shlomiv/6295921 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn first-out [& fns] | |
(let [fs (atom []) | |
ret (promise) | |
terminate (fn [x] (println "cancling.." ) (doall (map future-cancel @fs)) (deliver ret x))] | |
(reset! fs (doall | |
(map (fn [x] (future-call #(terminate (x)))) fns ))) | |
@ret | |
)) | |
(defn wait-for [n s] | |
"this time, return the value" | |
(fn [] (print "start...") (flush) (Thread/sleep n) (print s) (flush) s)) | |
(first-out (wait-for 1000 "long") (wait-for 500 "short")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment