Skip to content

Instantly share code, notes, and snippets.

@rm-hull
Forked from martintrojer/sin.cljs
Last active December 30, 2015 01:49
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 rm-hull/7758795 to your computer and use it in GitHub Desktop.
Save rm-hull/7758795 to your computer and use it in GitHub Desktop.
Sample core.async - see it running in the browser: http://programming-enchiladas.destructuring-bind.org/rm-hull/7758795
(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)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment