Skip to content

tolitius/wracer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

alt! racing web with core.async/clojurescript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published