Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Clojure's core.async similar to Jane Street's OCaml Core Async?

In this blog post the author writes:

However, Grenchman is built on the Core and Async libraries from Jane Street, one of the largest industrial users of OCaml. Async allows for monadic faux-concurrency that avoids a lot of the callback headaches of other event-driven tools, but it is fairly monolithic.

On the Jane Street Documentation Page for Core Async they describe it as:

In particular, we think that Async does a better of controlling the concurrency of your program, making it easier to reason about possible race conditions.

My question is - are there similarities between core.async in Clojure and Core Async in OCaml? I ask because the 'faux concurrency to avoid callback headaches' sounds quite similar to the application of core.async in Clojure.

like image 416
hawkeye Avatar asked Oct 14 '13 21:10

hawkeye


1 Answers

I cannot detect major similarities. The concept of Clojure's core.async seems to be mostly based upon Go's concurrency model - many of the names are the same, like channels for communication and even the go macro for executing code asynchronously, like Go's keyword that the language itself is named for.

The concept of Jane Street's Async on the other hand is summarized in this sentence from the introductory documentation:

In a nutshell, the idea is to use non-preemptive user-level threads and first-class blocking operations with blocking expressed in the type system.

It uses the special type Deferred.t to communicate results of asynchronous computations which is more similar to Clojure futures than to channels. It also completely eschews OS threads and uses user threads insteads, whereas core.async does make use of OS threads (at least if they're available).

Edit: Upon some further investigations, there is a clear similarity in that both libraries have a focus on providing means for combining multiple blocking operations without tying up OS threads. And Async does also provide (besides Deferred.t) channels through the Pipe module.

like image 145
Rörd Avatar answered Nov 22 '22 22:11

Rörd