Created
October 18, 2013 10:42
-
-
Save tangrammer/7039755 to your computer and use it in GitHub Desktop.
a clojure core.async proposal solution to this question: "Clojure (script): macros to reason about async operations synchronously" http://stackoverflow.com/questions/11171066/clojure-script-macros-to-reason-about-async-operations-synchronously
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 fourclojure.stack | |
(require [clojure.core.async :as async :refer :all])) | |
(defn update-sidebar! [new-data] | |
(println "you have updated the sidebar with this data:" new-data)) | |
(defn async-handler [the-channel data-recieved] | |
(put! the-channel data-recieved) | |
) | |
(defn make-ajax-call [url data-to-send] | |
(let [the-channel (chan)] | |
(go | |
(<! (timeout 2000)); wait 2 seconds to response | |
(async-handler the-channel (str "return value with this url: " url))) | |
the-channel | |
) | |
) | |
(update-sidebar! (<!! (make-ajax-call "/fetch-new-data" {}))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and the project configuration: