Last active
August 29, 2015 13:57
-
-
Save tmoerman/9621689 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 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