1

I am working on my first ClojureScript project, and I am not able to find core.async functions/macros I am used to in Clojure; like thread, <!!. (I checked the source code in github as well and they do not exist in the cljs source)

Is there some reference I can use to find the differences between the usage of core.async in Clojure and ClojureScript?

Also, how do I perform a blocking get operation from a chan outside a go block in cljs? Looks like cljs does not have any blocking operations in core.async

Or just start a separate thread for a function which is not going to return any value?

Google doesn't really seem to provide a lot of info about core.async in cljs

Any help or pointers would be appreciated!

pvik
  • 105
  • 5

1 Answers1

0

core.async is a separate library. Make your project.clj look like this:

(defproject flintstones "0.1.0-SNAPSHOT"
  :min-lein-version "2.7.1"
  :dependencies [[org.clojure/clojure "1.9.0"]
                 [org.clojure/clojurescript "1.10.238"]
                 [org.clojure/core.async "0.4.474"]]
...

and your CLJS namespace should define something like:

(ns tst.flintstones.dino
  (:require
    [cljs.test :refer-macros [deftest is async use-fixtures]]
    [cljs.core.async :as async]
    [dinoPhony] ))

and code like:

 (let [ch (async/chan)]
    (async/go (async/>! ch 42))
    (println "dino: async result:" (async/go (async/<! ch)))

Please see this template project for a working example.

Alan Thompson
  • 29,276
  • 6
  • 41
  • 48
  • Thanks Alan, I know that `core.async` is a seperate package, and I use it in several clojure projects. However, there seems to be a lot of discrepancies in what the library offers in clj and cljs (like lack of `thread` macro in cljs and no blocking operations). I was trying to see if there was any place where all the differences were documented. – pvik Sep 17 '18 at 21:57
  • @pvik only significant difference is that JavaScript has no threads, so none of the thread operations are there. You have to use CSP as in the answer to the linked duplicate. – Jared Smith Sep 18 '18 at 13:02