Don't keep reading on EOF
This commit is contained in:
parent
630161441b
commit
ed996f6f41
1 changed files with 38 additions and 35 deletions
|
|
@ -38,41 +38,44 @@
|
||||||
:json #(cheshire/parse-string-strict % true))]
|
:json #(cheshire/parse-string-strict % true))]
|
||||||
(try
|
(try
|
||||||
(loop []
|
(loop []
|
||||||
(let [reply (read stdout)
|
(let [reply (try (read stdout)
|
||||||
id (get reply "id")
|
(catch java.io.EOFException _
|
||||||
id (bytes->string id)
|
::EOF))]
|
||||||
value* (find reply "value")
|
(when-not (identical? ::EOF reply)
|
||||||
value (some-> value*
|
(let [id (get reply "id")
|
||||||
second
|
id (bytes->string id)
|
||||||
bytes->string
|
value* (find reply "value")
|
||||||
read-fn)
|
value (some-> value*
|
||||||
status (get reply "status")
|
second
|
||||||
status (set (map (comp keyword bytes->string) status))
|
bytes->string
|
||||||
done? (contains? status :done)
|
read-fn)
|
||||||
error? (contains? status :error)
|
status (get reply "status")
|
||||||
value (if error?
|
status (set (map (comp keyword bytes->string) status))
|
||||||
(let [message (or (some-> (get reply "ex-message")
|
done? (contains? status :done)
|
||||||
bytes->string)
|
error? (contains? status :error)
|
||||||
"")
|
value (if error?
|
||||||
data (or (some-> (get reply "ex-data")
|
(let [message (or (some-> (get reply "ex-message")
|
||||||
bytes->string
|
bytes->string)
|
||||||
read-fn)
|
"")
|
||||||
{})]
|
data (or (some-> (get reply "ex-data")
|
||||||
(ex-info message data))
|
bytes->string
|
||||||
value)
|
read-fn)
|
||||||
chan (get @chans id)
|
{})]
|
||||||
out (some-> (get reply "out")
|
(ex-info message data))
|
||||||
bytes->string)
|
value)
|
||||||
err (some-> (get reply "err")
|
chan (get @chans id)
|
||||||
bytes->string)]
|
out (some-> (get reply "out")
|
||||||
(when (or value* error?) (async/put! chan value))
|
bytes->string)
|
||||||
(when (or done? error?) (async/close! chan))
|
err (some-> (get reply "err")
|
||||||
(when out
|
bytes->string)]
|
||||||
(binding [*out* out-stream]
|
(when (or value* error?) (async/put! chan value))
|
||||||
(println out)))
|
(when (or done? error?) (async/close! chan))
|
||||||
(when err (binding [*out* err-stream]
|
(when out
|
||||||
(println err))))
|
(binding [*out* out-stream]
|
||||||
(recur))
|
(println out)))
|
||||||
|
(when err (binding [*out* err-stream]
|
||||||
|
(println err))))
|
||||||
|
(recur))))
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(binding [*out* err-stream]
|
(binding [*out* err-stream]
|
||||||
(prn e))))))
|
(prn e))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue