Visualizes one of the coolest core.async features: alt!, by "selecting" on several HTTP GET and a timeout channels, and rendering the winner's stats and HTML response.
HTTP GETs are also async, and merely put their responses on a channel, which they then return.
Here is the race (clojurescript):
(defn race [q]
(let [t (timeout timeout-ms)
start (now)]
(go
(alt!
(GET (str "/yahoo?q=" q)) ([v] (winner :.yahoo v (took start)))
(GET (str "/bing?q=" q)) ([v] (winner :.bing v (took start)))
(GET (str "/google?q=" q)) ([v] (winner :.google v (took start)))
t ([v] (show-timeout timeout-ms))))))
Once a winner is determined or a timeout channel returns nil ("times out"), the response is rendered:
It of course has nothing to do with real world benchmarking of any kind, but it does serve as an interactive visual of "alt!" doing its magic.
lein ring server
copyright © 2014 tolitius
distributed under the Eclipse Public License, the same as Clojure.