Skip to content

Instantly share code, notes, and snippets.

@manicolosi
Last active October 30, 2015 20:21
Show Gist options
  • Save manicolosi/13bd7bc89879987f0c1f to your computer and use it in GitHub Desktop.
Save manicolosi/13bd7bc89879987f0c1f to your computer and use it in GitHub Desktop.
(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