Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns modern-cljs.procman
- (:require [cljs.core.async :as async
- :refer [<! >! >!! <!! timeout chan take! put!]]
- [domina :as dom])
- (:require-macros
- [cljs.core.async.macros :refer [go]]))
- (def c (chan))
- (defn render [q]
- (apply str
- (for [p (reverse q)]
- (str "<div class='proc-" p "'>Process " p "</div>"))))
- (defn peekn
- "Returns vector of (up to) n items from the end of vector v"
- [v n]
- (if (> (count v) n)
- (subvec v (- (count v) n))
- v))
- (defn ^:export init []
- (when (and js/document
- (.-getElementById js/document)))
- (go (while true (<! (timeout 250)) (>! c 1)))
- (go (while true (<! (timeout 1000)) (>! c 2)))
- (go (while true (<! (timeout 1500)) (>! c 3)))
- (let [el (dom/by-id "other")
- out (dom/by-id "greeting")]
- (go (loop [q []]
- (dom/set-html! out (render q))
- (recur (-> (conj q (<! c)) (peekn 10)))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement