Fix nil return value
This commit is contained in:
parent
ed996f6f41
commit
016e20dc52
5 changed files with 27 additions and 9 deletions
|
|
@ -64,12 +64,20 @@
|
|||
(ex-info message data))
|
||||
value)
|
||||
chan (get @chans id)
|
||||
promise? (instance? clojure.lang.IPending chan)
|
||||
out (some-> (get reply "out")
|
||||
bytes->string)
|
||||
err (some-> (get reply "err")
|
||||
bytes->string)]
|
||||
(when (or value* error?) (async/put! chan value))
|
||||
(when (or done? error?) (async/close! chan))
|
||||
(when (or value* error?)
|
||||
(if promise?
|
||||
(deliver chan value)
|
||||
(async/put! chan value)))
|
||||
(when (or done? error?)
|
||||
(if promise?
|
||||
(deliver chan nil) ;; some ops don't receive a value but are
|
||||
;; still done.
|
||||
(async/close! chan)))
|
||||
(when out
|
||||
(binding [*out* out-stream]
|
||||
(println out)))
|
||||
|
|
@ -91,14 +99,15 @@
|
|||
:edn pr-str
|
||||
:json cheshire/generate-string)
|
||||
id (next-id)
|
||||
chan (async/chan)
|
||||
chan (if async? (async/chan)
|
||||
(promise))
|
||||
_ (swap! chans assoc id chan)
|
||||
_ (write stream {"id" id
|
||||
"op" "invoke"
|
||||
"var" (str pod-var)
|
||||
"args" (write-fn args)})]
|
||||
(if async? chan ;; TODO: https://blog.jakubholy.net/2019/core-async-error-handling/
|
||||
(let [v (async/<!! chan)]
|
||||
(let [v @chan]
|
||||
(if (instance? Throwable v)
|
||||
(throw v)
|
||||
v)))))
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@
|
|||
{"name" "assoc"}
|
||||
{"name" "error"}
|
||||
{"name" "print"}
|
||||
{"name" "print-err"}]}]
|
||||
{"name" "print-err"}
|
||||
{"name" "return-nil"}]}]
|
||||
"ops" {"shutdown" {}}})
|
||||
(recur))
|
||||
:invoke (let [var (-> (get message "var")
|
||||
|
|
@ -107,7 +108,12 @@
|
|||
"id" id})
|
||||
(write
|
||||
{"status" ["done"]
|
||||
"id" id})))
|
||||
"id" id}))
|
||||
pod.test-pod/return-nil
|
||||
(write
|
||||
{"status" ["done"]
|
||||
"id" id
|
||||
"value" "nil"}))
|
||||
(recur))
|
||||
:shutdown (System/exit 0))))))))
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
(is (= '[{:a 1, :b 2}
|
||||
6
|
||||
[1 2 3 4 5 6 7 8 9]
|
||||
"Illegal arguments / {:args (1 2 3)}"] ret))
|
||||
"Illegal arguments / {:args (1 2 3)}"
|
||||
nil] ret))
|
||||
(is (= "nil\n(\"hello\" \"print\" \"this\" \"debugging\" \"message\")\n" (str out)))
|
||||
(is (= "(\"hello\" \"print\" \"this\" \"error\")\n" (str err)))))
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
(is (= '[{:a 1, :b 2}
|
||||
6
|
||||
[1 2 3 4 5 6 7 8 9]
|
||||
"Illegal arguments / {:args (1 2 3)}"] ret))
|
||||
"Illegal arguments / {:args (1 2 3)}"
|
||||
nil] ret))
|
||||
(is (= "nil\n(\"hello\" \"print\" \"this\" \"debugging\" \"message\")\n" (str out)))
|
||||
(is (= "(\"hello\" \"print\" \"this\" \"error\")\n" (str err)))))
|
||||
|
|
|
|||
|
|
@ -21,4 +21,5 @@
|
|||
[(pod/assoc {:a 1} :b 2)
|
||||
(pod.test-pod/add-sync 1 2 3)
|
||||
@stream-results
|
||||
ex-result]")
|
||||
ex-result
|
||||
(pod.test-pod/return-nil)]")
|
||||
|
|
|
|||
Loading…
Reference in a new issue