Last active
May 17, 2016 00:40
-
-
Save Risto-Stevcev/aaadc9d8bd11c19e36d944457be228c1 to your computer and use it in GitHub Desktop.
Converting callbacks to use core-async channels in ClojureScript
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
(ns callback-to-core-async.core | |
(:require-macros [cljs.core.async :refer go]) | |
(:require [ajax.core :refer [GET]] | |
[cljs.core.async :refer [<! put! chan]])) | |
(defn http-get [url] | |
(let [out (chan) | |
handler #(put! out %1)] | |
(GET url {:handler handler :error-handler handler}) | |
out)) | |
(enable-console-print!) | |
(go | |
(let [result (<! (http-get "http://jsonplaceholder.typicode.com/users/1"))] | |
(println result))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment