Last active
March 26, 2017 10:39
-
-
Save alexanderjamesking/b3221658538514655142abc2c8821e20 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(ns batchreq.core | |
(:refer-clojure :exclude [map reduce into partition partition-by take merge]) | |
(:require [clojure.core.async :refer :all :as async] | |
[clj-http.client :as client]) | |
(:use taoensso.timbre | |
taoensso.timbre.profiling)) | |
(defnp http-get [id] | |
(client/get (format "http://fssnip.net/%d" id)) | |
id) | |
(defnp sequentially [rn res] | |
(doseq [i rn] | |
; sequential http-get for each item in the range | |
(swap! res conj (http-get i)))) | |
(defnp in-parallel [rn res] | |
(let [channel (chan)] | |
(doseq [i rn] | |
; send the http-get requests to the channel (non blocking) | |
(go (>! channel (http-get i)))) | |
(doseq [i rn] | |
; take result from the channel (blocks if nothing is available) | |
(swap! res conj (<!! channel))))) | |
(defn request-snippets [f] | |
(let [rn (range 10 30) | |
res (atom [])] | |
(profile :info :Arithmetic (f rn res)) | |
(info @res) | |
@res)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment