Last active
December 21, 2015 07:59
-
-
Save shlomiv/6275516 to your computer and use it in GitHub Desktop.
this version is useful for side-effects only (like printing)
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 []) | |
terminate (fn [] (println "cancling..") (doall (map future-cancel @fs)))] | |
(reset! fs (doall | |
(map (fn [x] (future-call #((x) (terminate)))) fns ))))) | |
(defn wait-for [n s] | |
(fn [] (print "start...") (flush) (Thread/sleep n) (print s) (flush))) | |
(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