Core.async - Martin Trojer's Sine Generator

core.async

Sample core.async - see it running in the browser: http://programming-enchiladas.destructuring-bind.org/rm-hull/7758795

2 Dec 2013 by rm-hull
rm-hull/7758795
sin.cljs
(ns async-test.sinewave.core
  (:require [cljs.core.async :refer [<! >! chan timeout]])
  (:require-macros
    [cljs.core.async.macros :as m :refer [go]]))


(defn sin-vals [offset]
  (map #(Math/sin %) (iterate (partial + 0.1) offset)))

(let [events (chan)]

  ;; produce seqs of sine values
  (go (loop [n 0]
           (<! (timeout 200))
           (>! events (sin-vals n))
           (recur (inc n))))

  (go
    (dotimes [_ 10]
      ;; Draw on screen
      (println
       (map (fn [x y] {:x x :y y})
            (range 3)
            (take 3 (<! events)))))))