It's not reached an official release yet, but core.async looks like it might be an interesting way of solving your problem - and other asynchronous problems, very neatly.
The leiningen incantation for core.async is (currently) as follows:
[org.clojure/core.async "0.1.0-SNAPSHOT"]
And here's some code to make a function that will take a number of time-consuming functions, and block until one of them returns.
(require '[clojure.core.async :refer [>!! chan alts!! thread]])) (defn return-first [& ops] (let [v (map vector ops (repeatedly chan))] (doseq [[op c] v] (thread (>!! c (op)))) (let [[value channel] (alts!! (map second v))] value))) ;; Make sure the function returns what we expect with a simple Thread/sleep (assert (= (return-first (fn [] (Thread/sleep 3000) 3000) (fn [] (Thread/sleep 2000) 2000) (fn [] (Thread/sleep 5000) 5000)) 2000))
In the sample above:
chan creates an asynchronous channel >!! puts a value onto a channel thread executes the body in another thread alts!! takes a vector of channels, and returns when a value appears on any of them
There's way more to it than this, and I'm still getting my head round it, but there's a walkthrough here: https://github.com/clojure/core.async/blob/master/examples/walkthrough.clj
And David Nolen's blog has some great, if mind-boggling, posts on it (http://swannodette.github.io/)
Edit
Just seen that Michał Marczyk has answered a very similar question, but better, here, and it allows you to cancel/short-circuit. with Clojure threading long running processes and comparing their returns