0a312b4f40
This is a well-worn idea: use a `promise-channel` of `[result nil]` or `[nil error]` pairs. The `go-pair` and `<?` macros handle catching exceptions (important, given that synchronous CLJ code expects to throw rather than return an error promise or similar), allowing code like: ``` (go-pair (let [result (<? (pair-chan-fn))] (when (not result) (throw (Exception. "No result!"))) (transform result))) ``` to be expressed naturally. These are the equivalents of `async` and `await` in JS. The implementation is complicated by significant incompatibilities between CLJ and CLJS. The solution presented here takes care to separate the macro definitions into CLJ. Sadly, this requires namespacing the per-environment symbols explicitly; but we hope to minimize such code in files like this. The most significant restriction to this approach is that consumers must require the transitive dependencies of the macro-defining modules. See the included tests (both CLJ and CLJS) for the appropriate incantations (for pair-chan, core.async, and test).
56 lines
3.1 KiB
Clojure
56 lines
3.1 KiB
Clojure
(defproject lib "0.1.0-SNAPSHOT"
|
|
:description "A persistent, embedded knowledge base inspired by Datomic and DataScript."
|
|
:url "https://github.com/mozilla/datomish"
|
|
:license {:name "Mozilla Public License Version 2.0"
|
|
:url "https://github.com/mozilla/datomish/blob/master/LICENSE"}
|
|
:dependencies [[org.clojure/clojurescript "1.9.89"]
|
|
[org.clojure/clojure "1.8.0"]
|
|
[org.clojure/core.async "0.2.385"]
|
|
[jamesmacaulay/cljs-promises "0.1.0"]]
|
|
|
|
:cljsbuild {:builds {:release {
|
|
:source-paths ["src"]
|
|
:assert false
|
|
:compiler {:output-to "release-js/datomish.bare.js"
|
|
:optimizations :advanced
|
|
:pretty-print false
|
|
:elide-asserts true
|
|
:output-wrapper false
|
|
:parallel-build true}
|
|
:notify-command ["release-js/wrap_bare.sh"]}
|
|
:advanced {:source-paths ["src"]
|
|
:compiler {:output-to "target/advanced/datomish.js"
|
|
:optimizations :advanced
|
|
:source-map "target/advanced/datomish.js.map"
|
|
:pretty-print true
|
|
:recompile-dependents false
|
|
:parallel-build true
|
|
}}
|
|
:test {
|
|
:source-paths ["src" "test"]
|
|
:compiler {:output-to "target/test/datomish.js"
|
|
:output-dir "target/test"
|
|
:main datomish.test
|
|
:optimizations :none
|
|
:source-map true
|
|
:recompile-dependents false
|
|
:parallel-build true
|
|
:target :nodejs
|
|
}}
|
|
}
|
|
}
|
|
|
|
:profiles {:dev {:dependencies [[com.cemerick/piggieback "0.2.1"]
|
|
[org.clojure/tools.nrepl "0.2.10"]]
|
|
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
|
|
:plugins [[lein-cljsbuild "1.1.2"]
|
|
[lein-doo "0.1.6"]]
|
|
}}
|
|
|
|
:doo {:build "test"}
|
|
|
|
:clean-targets ^{:protect false} ["target"
|
|
"release-js/datomish.bare.js"
|
|
"release-js/datomish.js"]
|
|
)
|