|
| 1 | +;; [[file:~/github/intermediate-clojure-workshop/content/async/albums_stream.org::*Preamble][Preamble:1]] |
| 2 | +(ns icw.async.albums-stream |
| 3 | + (:require [clojure.core.async :as a |
| 4 | + :refer [chan go go-loop <! >! take! put!]] |
| 5 | + [icw.async.rlsc :as rlsc] |
| 6 | + [icw.data.gen :as data-gen])) |
| 7 | +;; Preamble:1 ends here |
| 8 | + |
| 9 | +;; [[file:~/github/intermediate-clojure-workshop/content/async/albums_stream.org::*Outline][Outline:2]] |
| 10 | +(defonce counter (atom 0)) |
| 11 | +(def observing-mapper (map (fn [e] |
| 12 | + (swap! counter inc) |
| 13 | + e))) |
| 14 | + |
| 15 | +(def in-ch (a/chan (a/dropping-buffer 32) observing-mapper)) |
| 16 | + |
| 17 | +(defonce enabled? (atom false)) |
| 18 | +(defonce quit? (atom false)) |
| 19 | + |
| 20 | +(defonce generator-loop |
| 21 | + (go-loop [stream (data-gen/get-albums-xs)] |
| 22 | + #_("Introduce an appropriate delay") |
| 23 | + (if-not @quit? |
| 24 | + (do |
| 25 | + (if @enabled? |
| 26 | + (a/>! in-ch #_(FIXME stream) :dummy)) |
| 27 | + (recur #_(FIXME stream) :dummy))))) |
| 28 | + |
| 29 | +(defn enable-stream! [] |
| 30 | + (reset! enabled? true)) |
| 31 | +(defn disable-stream! [] |
| 32 | + (reset! enabled? false)) |
| 33 | +;; Outline:2 ends here |
0 commit comments