0Pricing
Clojure Functional Programming & JVM Backend Development · Lesson

core.async Channels and Go Blocks

Beyond refs and atoms, core.async brings CSP-style concurrency to Clojure. This lesson teaches channels, go blocks, and coordinating asynchronous work with communicating processes.

core.async Channels and Go Blocks is a free Clojure Functional Programming & JVM Backend Development lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Clojure Functional Programming & JVM Backend Development learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why core.async

Atoms and refs manage shared state. core.async manages communication between independent processes using channels, inspired by CSP.

Requiring the Library

Pull in the core functions you will use.

(require '[clojure.core.async :as a
           :refer [chan go >! <! <!! >!!]])

Creating a Channel

A channel is a queue that processes use to hand off values. Create one with chan.

(def c (chan))
; an unbuffered channel

Go Blocks

A go block runs its body asynchronously on a thread pool, parking instead of blocking at channel operations.

(go (println "running asynchronously"))

Putting and Taking

Inside a go block, >! puts a value and <! takes one. Both park until the other side is ready.

(let [c (chan)]
  (go (>! c 42))
  (go (println "got" (<! c))))

Blocking Variants

Outside go blocks, use the double-bang forms >!! and <!!, which block the real thread. Useful at the REPL or in main.

(let [c (chan)]
  (go (>! c "hello"))
  (println (<!! c)))

Buffered Channels

Give a channel a buffer so puts do not park until the buffer is full. This decouples fast producers from slower consumers.

(def c (chan 10))
; up to 10 values can sit in the buffer

Selecting With alts!

alts! waits on several channels at once and proceeds with whichever is ready first, enabling timeouts and racing.

(go
  (let [[v ch] (a/alts! [c (a/timeout 1000)])]
    (println "got" v "from" ch)))

Closing Channels

Closing a channel signals no more values. Takes then return nil, which consumers use as a stop signal.

(a/close! c)
; subsequent <! returns nil

Pipelines of Processes

Wire go blocks together with channels to form a pipeline: each stage takes from one channel, transforms, and puts onto the next. State stays local to each process.

Channels vs Atoms

Use atoms/refs for shared mutable state; use channels to coordinate the flow of work between processes. They solve different problems and often combine.

Quick Check

Test your core.async knowledge.

Recap

You learned channels, go blocks, parking puts/takes, blocking variants, buffers, alts! for selection and timeouts, closing channels, and how channels complement atoms and refs.

Frequently asked questions

Is the “core.async Channels and Go Blocks” lesson free?

Yes — the full text of “core.async Channels and Go Blocks” is free to read here on the web, and the Clojure Functional Programming & JVM Backend Development course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Clojure Functional Programming & JVM Backend Development course, upgrade to CoddyKit PRO.

What will I learn in “core.async Channels and Go Blocks”?

Beyond refs and atoms, core.async brings CSP-style concurrency to Clojure. This lesson teaches channels, go blocks, and coordinating asynchronous work with communicating processes. You practise Clojure Functional Programming & JVM Backend Development with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Clojure Functional Programming & JVM Backend Development?

No prior experience is required. Clojure Functional Programming & JVM Backend Development on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “core.async Channels and Go Blocks” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Clojure Functional Programming & JVM Backend Development lesson?

Yes. Every Clojure Functional Programming & JVM Backend Development lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Refs, Agents, Atoms for State
  2. Software Transactional Memory (STM)
  3. Promises, Futures & Async Operations
  4. core.async Channels and Go Blocks
← Back to Clojure Functional Programming & JVM Backend Development