Skip to content

Instantly share code, notes, and snippets.

@shlomiv
Last active December 21, 2015 07:59
Show Gist options
  • Save shlomiv/6275516 to your computer and use it in GitHub Desktop.
Save shlomiv/6275516 to your computer and use it in GitHub Desktop.
this version is useful for side-effects only (like printing)
(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