Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 1.42 KB

README.md

File metadata and controls

43 lines (30 loc) · 1.42 KB

wracer

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.

show me

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:

wracer in action

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.

usage / start the app

lein do clean, ring server

license

copyright © 2014 tolitius

distributed under the Eclipse Public License, the same as Clojure.