Almost written at the same time

There have been several interesting posts about the implementation of Clojure’s core.async. This post in particular is really good, diving into the implementation and even answering some of the questions that were raised in an unrelated post that asks about the implementation of new channel types. The author takes a small go block and analyses the generated code, looking in detail at the state machine and the support code in the runtime library. Channels are based on the Handler protocol which itself is quite interesting. It allows the channel to either do its action synchronously, avoiding any blocking and letting the caller take responsibility for continuing the computation, or to instead queue a closure which will be called when a value is available. This closure is used to make the state machine take another transition when the necessary values are ready. Understanding the implementation helps one understand the trade-offs involved in using this language feature.

The author has also written this illuminating post on the timeouts available in core.async.

ClojureScript is a variant of Clojure that compiles down to JavaScript, and there are some interesting examples here and here of programs that use the core.async variant that runs on top of JavaScript. They demonstrate how it is possible to share the single threaded browser UI between worker tasks.

This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s