Chapter 6. Communication with core.async

Now that you know how to use libraries, you can get to know a very nice library called core.async, which allows asynchronous and concurrent communication through channels. This allows independent threads of activity to communicate with one another and is an important tool for fast processing and communication. We’ll start exploring how it works with the help of Alice and a sample project.

As Alice continued on her adventure in Wonderland, she happened upon a tea party. It wasn’t just a regular tea party, it was a mad tea party (and by mad I mean crazy). The Mad Hatter, March Hare, and Dormouse were at the table when Alice joined them.

To create a new project, follow these steps:

  1. Run the following command:

    lein new async-tea-party
  2. Go into the new directory that was created:

    cd async-tea-party

Now that you have the project created, you need to modify the project.clj file to include the core.async library. You can go to the GitHub project page for core.async to check for the latest version. It will look something like Figure 6-1.

lvcl 0601
Figure 6-1. GitHub core-async

Edit your project.clj file to include the correct dependency info for the latest core-async library:

(defproject async-tea-party "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html" ...

Get Living Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.