Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active November 18, 2017 16:37
Show Gist options
  • Save mfikes/3e399ede6edd71c2e748c0da3f213bb7 to your computer and use it in GitHub Desktop.
Save mfikes/3e399ede6edd71c2e748c0da3f213bb7 to your computer and use it in GitHub Desktop.
Unified core.async namespace

core.async 0.3.465 was recently released with ASYNC-119 which makes the macros available in the cljs.core.async namespace.

With ClojureScript clojure Namespace Aliasing, along with ClojureScript's ability to implicitly refer macros (see ClojureScript Macro Sugar), this means you can write code that works across Clojure and ClojureScript.

Furthermore, this has been ported and released in Andare 0.8.0, so the same code works in self-hosted ClojureScript!

Here is an example:

Fetch the Andare 0.8.0 JAR using boot

boot -d andare:0.8.0

Then make use of this new capability with either Planck or Lumo:

$ planck -qD andare:0.8.0
cljs.user=> (require '[clojure.core.async :refer [chan <! >! go]])
nil
cljs.user=> (def c (chan))
#'cljs.user/c
cljs.user=> (go (prn (<! c)))
#object[cljs.core.async.impl.channels.ManyToManyChannel]
cljs.user=> (go (>! c :hello))
#object[cljs.core.async.impl.channels.ManyToManyChannel]
:hello

Note that the require form looks exactly like the one you would use in Clojure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment