On Github AshtonKem / async_presentation
Ashton A. Kemerling
Defining Functions.
(defn fib [x]
(if (<= x 0)
1
(* x (fib (- x 1))))))
Calling Functions.
(fib 24)
(defn fib [x]
(let [positive? (>= x 0)
sub-call (fib (- x 1))]
(if positive?
(* x sub-call)
1)))
All variables are immutable. Re-defining them in the let block shadows previous definition.
Channels can be configured, but they are untyped
Two kinds of operations, blocking and parking
(let [c1 (chan)
c2 (chan)]
(go (while true
(let [[v ch] (alts! [c1 c2])]
(println "Read" v "from" ch))))
(go (>! c1 "hi"))
(go (>! c2 "there")))
The alts! and alts!! methods can select from multiple channels. Used to replace the select idiom from Go
(let [c1 (chan)
c2 (chan)]
(thread (while true
(let [[v ch] (alts!! [c1 c2])]
(println "Read" v "from" ch))))
(>!! c1 "hi")
(>!! c2 "there"))
Courtesy of Swannodette
10,000 Processes