Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions src/nodely/api/v0.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(:require
[nodely.data]
[nodely.engine.applicative :as applicative]
[nodely.engine.async.manifold-engine :as engine.async.manifold-engine]
[nodely.engine.async.virtual-futures-engine :as engine.async.virtual-futures-engine]
[nodely.engine.core :as engine-core]
[nodely.engine.core-async.iterative-scheduling-engine :as engine.core-async.iterative-scheduling-engine]
Expand Down Expand Up @@ -57,15 +58,6 @@
nodely.engine.core-async.lazy-scheduling]
:cause e}))))

(def manifold-failure
(delay
(try (require 'nodely.engine.manifold)
(catch Exception e
{:msg "Could not locate manifold on classpath."
::error :missing-ns
::requested-namespaces '[nodely.engine.manifold]
:cause e}))))

(def promesa-failure
(delay
(try (require 'nodely.engine.applicative.promesa)
Expand All @@ -81,9 +73,8 @@
::eval-key-channel true}
:core-async.iterative-scheduling {::protocol-engine? true
::instance-constructor engine.core-async.iterative-scheduling-engine/->CoreAsyncIterativeSchedulingEngine}
:async.manifold {::ns-name 'nodely.engine.manifold
::opts-fn (constantly nil)
::enable-deref manifold-failure}
:async.manifold {::protocol-engine? true
::instance-constructor engine.async.manifold-engine/->AsyncManifoldEngine}
:applicative.promesa {::ns-name 'nodely.engine.applicative
::opts-fn #(assoc % ::applicative/context
(var-get (resolve 'nodely.engine.applicative.promesa/context)))
Expand Down
44 changes: 44 additions & 0 deletions src/nodely/engine/async/manifold_engine.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
(ns nodely.engine.async.manifold-engine
(:require
[nodely.engine.protocols :as engine.protocols]))

(def ^:private impl-ns 'nodely.engine.manifold)

(def enable-deref
"A delay yielding nil when the manifold implementation can be loaded, or a
failure map describing the missing dependency otherwise."
(delay
(try
(require impl-ns)
nil
(catch Exception e
{:msg "Could not locate manifold on classpath."
::error :missing-ns
::requested-namespaces [impl-ns]
:cause e}))))

(defn- impl
"Lazily loads the implementation namespace and resolves `fn-name` within it."
[fn-name]
(requiring-resolve (symbol (name impl-ns) (name fn-name))))

(deftype AsyncManifoldEngine []
engine.protocols/Engine
(-eval [_engine env k _opts]
((impl 'eval) env k))

(-eval-key [_engine env k _opts]
((impl 'eval-key) env k))

(-eval-key-channel [_engine _env _k _opts]
(throw (UnsupportedOperationException.
"Engine :async.manifold does not support eval-key-channel.")))

(-eval-key-channel-supported? [_engine]
false)

(-enable-deref [_engine]
enable-deref)

(-prepare-opts [_engine _opts]
nil))
2 changes: 1 addition & 1 deletion test/nodely/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
5
(api/eval-key env :z {::api/engine :async.manifold})))))
(testing-require-delay
nodely.engine.manifold nodely.api.v0/manifold-failure
nodely.engine.manifold nodely.engine.async.manifold-engine/enable-deref
"Kaboom! We don't have manifold for pretend" :test-manifold-failure
(t/testing "without manifold on the classpath"
(t/testing "attempting to use manifold"
Expand Down