Book Image

Clojure Reactive Programming

Book Image

Clojure Reactive Programming

Overview of this book

Table of Contents (19 chapters)
Clojure Reactive Programming
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Bibliography
Index

Rewriting the stock market application with core.async


By using an example we are familiar with, we are able to focus on the differences between all approaches discussed so far, without getting side tracked with new, specific domain rules.

Before we dive into the implementation, let's quickly do an overview of how our solution should work.

Just like in our previous implementations, we have a service from which we can query share prices. Where our approach differs, however, is a direct consequence of how core.async channels work.

On a given schedule, we would like to write the current price to a core.async channel. This might look like so:

This process will continuously put prices in the out channel. We need to do two things with each price: display it and display the calculated sliding window. Since we like our functions decoupled, we will use two go blocks, one for each task:

Hold on. There seems to be something off with our approach. Once we take a price from the output channel, it is not...