Skip to content

Instantly share code, notes, and snippets.

@tmoerman
Last active August 29, 2015 13:57
Show Gist options
  • Save tmoerman/9621689 to your computer and use it in GitHub Desktop.
Save tmoerman/9621689 to your computer and use it in GitHub Desktop.
(ns scraps
(:require [clojure.core.async :refer [go timeout alts! chan <! >! put! <!!] :as async]
[org.httpkit.client :as http]))
;; sometimes yields nil
(def c (chan))
(defn http-get [url c]
(http/get url (fn [r] (put! c r)))
c)
(defn bla []
(go
(->>
(http-get "http://www.google.com" c)
<!
:body)))
(prn (<!! (bla)))
;; correct
(defn http-get-2 [url]
(let [c (chan)]
(http/get url (fn [r] (put! c r)))
c))
(defn request-2 [url]
(go
(->> url
(http-get-2)
<!
:body)))
(prn (<!! (request-2 "http://www.google.com")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment