Skip to content

Instantly share code, notes, and snippets.

@Risto-Stevcev
Last active May 17, 2016 00:40
Show Gist options
  • Save Risto-Stevcev/aaadc9d8bd11c19e36d944457be228c1 to your computer and use it in GitHub Desktop.
Save Risto-Stevcev/aaadc9d8bd11c19e36d944457be228c1 to your computer and use it in GitHub Desktop.
Converting callbacks to use core-async channels in ClojureScript
(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