Created
November 11, 2018 10:31
-
-
Save aibrahim/fd392d3efb3f31b091a8470d9e791d8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(:require [clojure.core.async :as a | |
:refer [>! <! >!! <!! go chan buffer close! thread alts! alts!! timeout]]) | |
(def URLS ["https://www.haskell.org" | |
"https://www.amazon.com" | |
"https://www.youtube.com"]) | |
(defn time-now [] | |
(. System (nanoTime))) | |
(defn elapsed [start end] | |
(/ (double (- end start)) 1000000000.0)) | |
(defn fetch [url ch] | |
(go | |
(let [start (time-now) | |
resp (slurp url) | |
n (count resp)] | |
(>! ch (format "%.2fs %7d %s" (elapsed start (time-now)) n url))))) | |
(defn -main | |
"I don't do a whole lot ... yet." | |
[& args] | |
(let [start (time-now) | |
ch (chan (count URLS))] | |
(doseq [url URLS] | |
(fetch url ch)) | |
(doseq [url URLS] | |
(println (<!! ch))) | |
(println (elapsed start (time-now))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment