Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
-
Upload
julian-gamble -
Category
Technology
-
view
512 -
download
0
description
Transcript of Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
![Page 1: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/1.jpg)
Paradigms of core.async
Clojure Conj Washington Nov 2014
Julian Gamble @juliansgamble
![Page 2: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/2.jpg)
Paradigms of core.async
Clojure Conj Washington Nov 2014
Julian Gamble @juliansgamble
![Page 3: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/3.jpg)
Paradigms of core.async
Clojure Conj Washington Nov 2014
Julian Gamble @juliansgamble
![Page 4: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/4.jpg)
Core.async is about:
![Page 5: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/5.jpg)
Core.async is about:
• queues in your application
![Page 6: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/6.jpg)
Core.async is about:
• queues in your application
• making your application simpler to reason about
![Page 7: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/7.jpg)
Benefits
In this talk you will gain an understanding of: • go blocks and how they do concurrency • core.async queues
![Page 8: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/8.jpg)
Benefits
In this talk you will gain an understanding of: • go blocks and how they do concurrency • core.async queues • go block timers • alts! macro and how it enables reading multiple queues
![Page 9: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/9.jpg)
Benefits
In this talk you will gain an understanding of: • go blocks and how they do concurrency • core.async queues • go block timers • alts! functions and how it enables reading multiple queues • how core.async processes work in ClojureScript • the visual impacts of how the core.async function enables
simple ‘process-level’ pauses • how to use core.async to separate out the calculation and
display parts of your code
![Page 10: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/10.jpg)
Benefits
In this talk you will gain an understanding of: • converting a Clojure code-base to ClojureScript • some tips for optimising ClojureScript
![Page 11: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/11.jpg)
What is core.async?
![Page 12: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/12.jpg)
What is core.async?
• A set of primitives for creating, reading and writing to queues
• A code walking macro that splices go blocks into state machines
![Page 13: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/13.jpg)
What is core.async?
• A set of primitives for creating, reading and writing to queues
• A code walking macro that splices go blocks into state machines
• A mechanism for asynchronous computation
• A library in both Clojure and ClojureScript
![Page 14: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/14.jpg)
What does core.async say about Clojure?
• core.async is implemented using a sophisticated Lisp macro - something only possible in a functional language
• in non-functional languages like Go and C# - CSP is achieved by compiler-extensions - whereas in a functional language like Clojure - this functionality comes as a mere library
![Page 15: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/15.jpg)
What is CSP?• Communicating Sequential Processes
• Comes out of process calculi – an attempt in the 1960’s and 1970’s to optimise computer usage through specialised algebra.
![Page 16: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/16.jpg)
What is CSP?• Communicating Sequential Processes
• Comes out of process calculi – an attempt in the 1960’s and 1970’s to optimise computer usage through specialised algebra.
• Based on message passing via channels
• Subject of 1978 Book by C.A.R. Hoare
![Page 17: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/17.jpg)
![Page 18: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/18.jpg)
basic example
-‐main function
first go block
second go blockmy-‐q>! <!
![Page 19: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/19.jpg)
2-basic-example
![Page 20: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/20.jpg)
2-basic-example
![Page 21: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/21.jpg)
2-basic-example
![Page 22: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/22.jpg)
2-basic-example
![Page 23: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/23.jpg)
2-basic-example
![Page 24: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/24.jpg)
basic example
[Demo]
![Page 25: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/25.jpg)
basic example
![Page 26: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/26.jpg)
basic multi-channel example-‐main function
first go block
third go block
my-‐q1>!
alts!
second go block my-‐q2>!
![Page 27: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/27.jpg)
![Page 28: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/28.jpg)
![Page 29: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/29.jpg)
![Page 30: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/30.jpg)
![Page 31: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/31.jpg)
basic multi-channel example
[DEMO]
![Page 32: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/32.jpg)
basic multi-channel example
![Page 33: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/33.jpg)
Tim Baldridge 10K processes
make-‐scene function
make-‐cell function10K
go block 1. Set colour 2. Paint canvas cell 3. Pause for random interval 4. Loop
![Page 34: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/34.jpg)
![Page 35: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/35.jpg)
![Page 36: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/36.jpg)
![Page 37: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/37.jpg)
[DEMO]
![Page 38: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/38.jpg)
![Page 39: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/39.jpg)
not 10K processes
makeScene function10K
makeCell function
mainLoop function
100
![Page 40: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/40.jpg)
![Page 41: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/41.jpg)
[DEMO]
![Page 42: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/42.jpg)
![Page 43: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/43.jpg)
![Page 44: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/44.jpg)
[DEMO]
![Page 45: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/45.jpg)
swanodette 10K processes
[go block] let block
[go block] render-‐loop render!‘render’ ‘queue’
[idx v] [idx v]
core.async channel parameter passed in during function call
![Page 46: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/46.jpg)
swanodette 10K processes
No more than 1024 pending puts are allowed on a single channel.
[go block] let block
[go block] render-‐loop render!‘render’ ‘queue’
[idx v] [idx v]
core.async channel parameter passed in during function call
![Page 47: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/47.jpg)
![Page 48: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/48.jpg)
![Page 49: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/49.jpg)
![Page 50: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/50.jpg)
![Page 51: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/51.jpg)
![Page 52: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/52.jpg)
[DEMO]
![Page 53: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/53.jpg)
![Page 54: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/54.jpg)
Events with core.async
-‐main function
listen to DOM event and return channel
[go block] print queue message
out/clicksput! <!
![Page 55: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/55.jpg)
JS event queue
![Page 56: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/56.jpg)
![Page 57: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/57.jpg)
Parallelism is not Concurrency
Imagine streams of execution in your program
![Page 58: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/58.jpg)
Parallelism is not Concurrency
Imagine streams of execution in your program
![Page 59: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/59.jpg)
Parallelism is not Concurrency
Imagine streams of execution in your program
![Page 60: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/60.jpg)
Parallelism1. For core.async "use it where ever you'd use a queue"
2. In the Tim Baldridge 10K processes example above - it is not explicitly using a queue
(<! (timeout (rand-int 1000)))))))
![Page 61: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/61.jpg)
Parallelism1. For core.async "use it where ever you'd use a queue"
2. In the Tim Baldridge 10K processes example above - it is not explicitly using a queue
(<! (timeout (rand-int 1000)))))))
3. But in the same example - it is implicitly using the queue of the core.async process scheduler - so you're still using a queue.
4. Go blocks are the lightweight equivalent of 'heavyweight' threads
![Page 62: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/62.jpg)
Parallelism1. For core.async "use it where ever you'd use a queue"
2. In the Tim Baldridge 10K processes example above - it is not explicitly using a queue
(<! (timeout (rand-int 1000)))))))
3. But in the same example - it is implicitly using the queue of the core.async process scheduler - so you're still using a queue.
4. Go blocks are the lightweight equivalent of 'heavyweight' threads
5. Heavyweight threads implicitly listen to the queue of the OS 'ready queue'
6. You're already implicitly using queues whenever you use threads.
![Page 63: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/63.jpg)
Quick recap• core.async is all about queues
![Page 64: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/64.jpg)
Quick recap• core.async is all about queues
• queues can used in your application for:
• parallelism
• separating the calculation from the display logic
• event handling
![Page 65: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/65.jpg)
[DEMO]
![Page 66: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/66.jpg)
Rich Hickey original ants demo
![Page 67: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/67.jpg)
Rich Hickey original ants demo-‐main function
animation agent
ant behaviour agent
evaporation agent
world symbol (vector of vectors)
send-‐off send-‐offsend-‐off
![Page 68: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/68.jpg)
![Page 69: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/69.jpg)
![Page 70: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/70.jpg)
![Page 71: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/71.jpg)
![Page 72: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/72.jpg)
Converting to ClojureScriptMissing functions in ClojureScript:
![Page 73: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/73.jpg)
Converting to ClojureScriptMissing functions in ClojureScript:
• defstruct - replace with a map
• alter - replace with swap!
![Page 74: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/74.jpg)
Converting to ClojureScriptMissing functions in ClojureScript:
• defstruct - replace with a map
• alter - replace with swap!
• sync
• dosync
• agent
![Page 75: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/75.jpg)
ants cljs no asyncanimate function
send-‐off-‐animation function
behave-‐ants function
evaporate function
world symbol (vector of vectors)
single call single callsingle call
requestAnimationFrame (callback)
![Page 76: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/76.jpg)
![Page 77: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/77.jpg)
[DEMO]
![Page 78: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/78.jpg)
![Page 79: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/79.jpg)
Adding core.async
![Page 80: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/80.jpg)
Adding core.async
• You can use a go block with a timeout queue in the same way you’d use a thread with a sleep function
![Page 81: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/81.jpg)
adding core.async
![Page 82: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/82.jpg)
adding core.async
![Page 83: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/83.jpg)
[DEMO]
![Page 84: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/84.jpg)
Using optimisations from David Nolen’s chambered example
• Macros for creating arrays and for-loops
• Underlying assumptions:
• cljs data structures are not yet fully performant - so consider replacing with arrays for speed
• The cljs compiler does not yet fully optimise higher order functions - the most efficient looping construct will be a for-loop macro that uses the loop function
![Page 85: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/85.jpg)
Using optimisations from David Nolen’s chambered example
![Page 86: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/86.jpg)
Using optimisations from David Nolen’s chambered example
![Page 87: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/87.jpg)
[DEMO]
![Page 88: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/88.jpg)
![Page 89: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/89.jpg)
Back to The Italian Job
• Who or what was the hero of the story?
![Page 90: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/90.jpg)
Summary• core.async is about using queues • core.async is about making your application simpler to reason about
![Page 91: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/91.jpg)
Summary• core.async is about using queues • core.async is about making your application simpler to reason about • classic applications are: user interface events, presentation loops,
parallelism in non-parallel environments • you can consider a multithreaded application a queue listener even if
it doesn’t appear to use queues
![Page 92: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/92.jpg)
Summary• core.async is about using queues • core.async is about making your application simpler to reason about • classic applications are: user interface events, presentation loops,
parallelism in non-parallel environments • you can consider a multithreaded application a queue listener even if
it doesn’t appear to use queues • in porting an application from Clojure to ClojureScript you have to
rethink your concurrency • There are lots of optimisations available to make ClojureScript
applications run faster • core.async is not a magic sauce you can sprinkle everywhere - know
when to use it
![Page 93: Clojure Conj 2014 - Paradigms of core.async - Julian Gamble](https://reader037.fdocuments.us/reader037/viewer/2022103116/5594455f1a28ab13738b456f/html5/thumbnails/93.jpg)
Questions?
Clojure Conj Nov 2014 Julian Gamble @juliansgamble
github.com/juliangamble/clojure-‐conj-‐2014-‐paradigms-‐of-‐core-‐async