简体   繁体   中英

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 J ane 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM