What is the difference between core.async and async/await implementations in other languages?


#1

Hi. C# has async/await feature and JavaScript will have it soon too. If compare async/await with core.async it looks like Clojure has channels which we can pass as values and naturally use as queues, but async/await doesn’t have such a feature. It looks like core.async has more powerful means than async/await implementations in C#/JavaScipt. Am I right? I would like to understand a conceptual difference between these async implementations.


#2

Hi @abtv,

Great question.

The short answer is that async/await is the underlying enabling factor for building core.async. If you have async/await, you could write the rest of core.async (or some other CSP) on top. It would include channels, buffers, and the rest of the API.

As an example: https://github.com/ubolonton/js-csp and this library by my friend: https://github.com/togakangaroo/gimgen. I’ve never had to use either of them. David Nolen wrote up an explanation of how JavaScript generators can be used to implement core.async: http://swannodette.github.io/2013/08/24/es6-generators-and-csp/

As for how Clojure implements them, Clojure’s go blocks are code-transforming macros. They convert the parking puts and takes (>! and <!) into callbacks. So what looks like synchronous code becomes asynchronous code. This has some downsides because the go macro cannot transform code across function calls (they can’t be made async). However, it looks like in JavaScript that as long as your function calls are also async functions (function*), the async pattern will cross function call boundaries.

I hope that answers your question! Thanks again.

Rock on!
Eric


#3

Thanks, @ericnormand for the answer!


#4

hi Eric!
Can you give a short example how would code look like with sync await in comparison with core.async channels ?
Thanks a lot!
Dan