Skip to content

Instantly share code, notes, and snippets.

@halgari
Created August 20, 2013 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halgari/6284406 to your computer and use it in GitHub Desktop.
Save halgari/6284406 to your computer and use it in GitHub Desktop.
(def a (chan))
(def b (chan))
(go
(>! b (<! a)))
(go
(>! a (<! b)))
(put! a 42)
(go
(while true
(<! (timeout 1))
(.log js/console "tick")))
@swannodette
Copy link

I'm trying yours, I was using the following:

(defn spool
  ([xs] (spool xs (chan)))
  ([xs out]
    (go (loop [xs (seq xs)]
          (if xs
            (do (>! out (first xs))
              (recur (next xs)))
            (do (close! out)
              :done))))
    out))

(let [xs (spool (into [] (range 1000000)) (chan (sliding-buffer 1000)))
      start (js/Date.)]
  (.log js/console "starting")
  (go (loop [last nil]
        (let [v (<! xs)] 
          (if-not (nil? v)
            (recur v)
            (do (.log js/console
                  "last value" last
                  " elapsed ms:" (- (.valueOf (js/Date.)) (.valueOf start)))
              :done))))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment