cljc-flow
v0.0.1
Published
A port of clojure.core.async.flow to squint. One .cljc source runs on the JVM and on squint.
Downloads
206
Readme
cljc-flow
cljc-flow is a port of clojure.core.async.flow to squint. This README calls clojure.core.async.flow "upstream". cljc-flow ports the code of core.async 1.10.874-alpha3. A .cljc file that uses flow runs on the JVM with upstream and in JavaScript with cljc-flow.
Motivation
I wanted to write flow code that runs on the JVM and in JavaScript. Upstream runs only on the JVM, because each process runs on a thread. Because squint compiles an ^:async fn to a JavaScript async function, cljc-flow uses promises where upstream uses threads, and a go macro is not necessary.
If upstream makes flow cross-platform, this project is no longer necessary.
Install
npm install cljc-flow(ns my.app
(:require #?(:clj [clojure.core.async :as a]
:cljs ["cljc-flow/core" :as a])
#?(:clj [clojure.core.async.flow :as flow]
:cljs ["cljc-flow/flow" :as flow])))Use
Use the upstream documentation: the flow guide and the API docs. Where cljc-flow is different from upstream, the docstring has a note that starts with cljc-flow:.
The tests show how to write one source for the two platforms. A parity suite in test/cljc_flow/ runs against core.async on the JVM and against cljc-flow on squint. harness.cljc has the code that is different on each platform. On squint, ::flow/stop is not upstream's keyword. upstream_flow_test.cljc shows an :as-alias require that gives the correct keywords.
Tests
bb test the parity suites on the JVM and on squint,
then the squint-only suite
bb test:browser the channel suites in headless ChromiumBefore the first bb test:browser, install a browser: npx playwright install chromium.
License
cljc-flow is a derivative work of clojure.core.async, under the same license.
