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

1

8

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.

Stranglehold answered 14/10, 2013 at 21:34 Comment(0)
R
8

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.

Raseda answered 14/10, 2013 at 22:21 Comment(2)
If I am a newcomer, is there one you recommend over the other ?Trichloromethane
@BlueTrin: Since one is an OCaml library and the one is for Clojure, I would suggest to choose based on whatever language you're more comfortable with/has other features or libraries (besides concurrency support) that you need. For good high-level concurrency libraries, both of these do the job, though Clojure in particular does also have good support for other concurrency models in the standard library.Maritsa

© 2022 - 2024 — McMap. All rights reserved.