invoke sync

This commit is contained in:
Michiel Borkent 2020-05-20 21:56:54 +02:00
parent 3b90c4ba59
commit 5a2f68c1ea
8 changed files with 31 additions and 12 deletions

View file

@ -11,6 +11,10 @@
:sha "cb96e80f6f3d3b307c59cbeb49bb0dcb3a2a780b"}}
:extra-paths ["test"]
:main-opts ["-m" "cognitect.test-runner"]}
:kaocha
{:extra-deps
{lambdaisland/kaocha {:mvn/version "1.0.632"}}
:main-opts ["-m" "kaocha.runner"]}
:test-pod
{:paths ["src" "test-pod"]
:main-opts ["-m" "pod.test-pod"]}}}

View file

@ -1,4 +1,7 @@
#!/usr/bin/env bash
clojure -A:test -n babashka.pods.jvm-test
#clojure -A:test:kaocha --focus babashka.pods.jvm-test
clojure -A:sci:test -n babashka.pods.sci-test
#clojure -A:sci:test:kaocha --focus babashka.pods.sci-test

View file

@ -9,5 +9,6 @@
([pod-id] (unload-pod pod-id {}))
([pod-id opts] (jvm/unload-pod pod-id opts)))
(defn invoke [pod-id sym args opts]
(jvm/invoke pod-id sym args opts))
(defn invoke
([pod-id sym args] (invoke pod-id sym args {}))
([pod-id sym args opts] (jvm/invoke pod-id sym args opts)))

View file

@ -119,8 +119,7 @@
"op" "invoke"
"var" (str pod-var)
"args" (write-fn args)})]
;; see: https://blog.jakubholy.net/2019/core-async-error-handling/
(cond handlers handlers
(cond handlers nil
:else (let [v @chan]
(if (instance? Throwable v)
(throw v)
@ -143,6 +142,12 @@
(doseq [[ns-name _] (:namespaces pod)]
(rns ns-name)))))
(def next-pod-id
(let [counter (atom 0)]
(fn []
(let [[o _] (swap-vals! counter inc)]
o))))
(defn load-pod
([pod-spec] (load-pod pod-spec nil))
([pod-spec {:keys [:remove-ns]}]
@ -207,8 +212,7 @@
(defn invoke-public [pod-id fn-sym args opts]
(let [pod (lookup-pod pod-id)]
(invoke pod fn-sym args opts)
nil))
(invoke pod fn-sym args opts)))
(defn unload-pod [pod-id]
(destroy pod-id))

View file

@ -24,5 +24,6 @@
([pod-id _opts]
(impl/unload-pod pod-id)))
(defn invoke [pod-id sym args opts]
(impl/invoke-public pod-id sym args opts))
(defn invoke
([pod-id sym args] (invoke pod-id sym args {}))
([pod-id sym args opts] (impl/invoke-public pod-id sym args opts)))

View file

@ -32,5 +32,6 @@
([pod-id _opts]
(impl/unload-pod pod-id)))
(defn invoke [pod-id sym args opts]
(impl/invoke-public pod-id sym args opts))
(defn invoke
([pod-id sym args] (invoke pod-id sym args {}))
([pod-id sym args opts] (impl/invoke-public pod-id sym args opts)))

View file

@ -23,13 +23,16 @@
(pod/do-twice (prn :foo))
(def callback-result (promise))
(pods/invoke "pod.test-pod" 'pod.test-pod/add-sync [1 2]
(pods/invoke pod-id 'pod.test-pod/add-sync [1 2]
{:handlers {:success
(fn [value]
(deliver callback-result value))}})
(def sync-invoke
(pods/invoke pod-id 'pod.test-pod/add-sync [1 2]))
(def error-result (promise))
(pods/invoke "pod.test-pod" 'pod.test-pod/add-sync ["1" 2]
(pods/invoke pod-id 'pod.test-pod/add-sync ["1" 2]
{:handlers
{:error (fn [m]
(deliver error-result m))}})
@ -45,6 +48,7 @@
pod-ns-name
assoc-result
add-result
sync-invoke
@stream-results
ex-result
nil-result

View file

@ -9,6 +9,7 @@
pod.test-pod
{:a 1, :b 2}
6
3
[1 2 3 4 5 6 7 8 9]
"Illegal arguments / {:args (1 2 3)}"
nil