Last active
October 30, 2015 20:21
-
-
Save manicolosi/13bd7bc89879987f0c1f to your computer and use it in GitHub Desktop.
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 my.promise-ring | |
(:require-macros [cljs.core.async.macros :refer [go go-loop]]) | |
(:require | |
[cljs.core.async :refer [promise-chan put! <! chan close!] :as async])) | |
; You Only Put Once | |
; YOPO | |
(enable-console-print!) | |
(defn get-from-that-ring [ch] | |
(go | |
(let [love (<! ch)] | |
(js/console.log "Here's the ring:" (pr-str love))))) | |
(defn make-a-promise [ch n] | |
(js/console.log "Putting it in:" n) | |
(put! ch (str "This much: " n))) | |
(defn run [] | |
(let [promise-ring (promise-chan)] | |
(js/window.setInterval (fn [& _] | |
(get-from-that-ring promise-ring)) | |
1000) | |
(js/window.setInterval (fn [& _] | |
(make-a-promise promise-ring (rand-int 100))) | |
1000))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment