This commit is contained in:
Michiel Borkent 2020-05-25 23:38:54 +02:00
parent 0142f418c2
commit f8fd641287
2 changed files with 9 additions and 7 deletions

View file

@ -53,7 +53,9 @@
id (bytes->string id)] id (bytes->string id)]
(if-let [cb (get @callbacks id)] (if-let [cb (get @callbacks id)]
(do (swap! callbacks dissoc id) (do (swap! callbacks dissoc id)
(cb reply)) ;; callbacks run in their own threads to not block the
;; processor
(future (cb reply)))
(let [value* (find reply "value") (let [value* (find reply "value")
value (some-> value* value (some-> value*
second second
@ -237,8 +239,11 @@
(let [id (next-id) (let [id (next-id)
prom (promise) prom (promise)
callback (fn [reply] callback (fn [reply]
(let [[name-sym vars] (bencode->namespace pod reply)] (try (let [[name-sym vars] (bencode->namespace pod reply)]
(callback {:name name-sym :vars vars :done prom})))] (callback {:name name-sym :vars vars :done prom}))
(catch Throwable e
(binding [*out* *err*]
(prn e)))))]
(swap! callbacks assoc id callback) (swap! callbacks assoc id callback)
(write (:stdin pod) (write (:stdin pod)
{"op" "load-ns" {"op" "load-ns"

View file

@ -6,8 +6,6 @@
(let [env (:env ctx) (let [env (:env ctx)
ns-name name ns-name name
sci-ns (sci/create-ns ns-name)] sci-ns (sci/create-ns ns-name)]
#_(swap! env assoc-in [:namespaces ns-name :obj]
sci-ns)
(sci/binding [sci/ns sci-ns] (sci/binding [sci/ns sci-ns]
(doseq [[var-name var-value] vars] (doseq [[var-name var-value] vars]
(cond (ifn? var-value) (cond (ifn? var-value)
@ -15,8 +13,7 @@
(sci/new-var (sci/new-var
(symbol (str ns-name) (str var-name)) var-value)) (symbol (str ns-name) (str var-name)) var-value))
(string? var-value) (string? var-value)
(sci/eval-string* ctx var-value)))) (sci/eval-string* ctx var-value)))))
#_(prn (get-in @env [:namespaces ns-name])))
(when done (deliver done :ok))) (when done (deliver done :ok)))
(def load-pod (def load-pod