wip
This commit is contained in:
parent
f021e2384b
commit
3859600a74
5 changed files with 58 additions and 22 deletions
41
README.md
41
README.md
|
|
@ -346,6 +346,47 @@ In the pod client:
|
||||||
nil
|
nil
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Deferred namespace loading
|
||||||
|
|
||||||
|
When your pod exposes multiple namespaces that can be used independently from
|
||||||
|
each other, consider implementing the `load-ns` op which allows the pod client
|
||||||
|
to load the namespace and process the client side code when it is loaded using
|
||||||
|
`require`. This will speed up the initial setup of the pod using `load-pod`.
|
||||||
|
|
||||||
|
In `describe` the pod will mark the namespaces as deferred:
|
||||||
|
|
||||||
|
``` clojure
|
||||||
|
{"name" "pod.lispyclouds.deferred-ns"
|
||||||
|
"defer" "true"}
|
||||||
|
```
|
||||||
|
|
||||||
|
When the user requires the namespace with `(require
|
||||||
|
'[pod.lispyclouds.deferred-ns])` the pod client will then send a message:
|
||||||
|
|
||||||
|
``` clojure
|
||||||
|
{"op" "load-ns"
|
||||||
|
"ns" "pod.lispyclouds.deferred-ns"
|
||||||
|
"id "..."}
|
||||||
|
```
|
||||||
|
|
||||||
|
upon which the pod will reply with the namespace data:
|
||||||
|
|
||||||
|
``` clojure
|
||||||
|
{"name" "pod.lispyclouds.deferred-ns"
|
||||||
|
"vars" [{"name" "myfunc" "code" "(defn my-func [])"}]}
|
||||||
|
```
|
||||||
|
|
||||||
|
If a deferred namespace depends on another deferred namespace, provide explicit
|
||||||
|
`require`s in `code` segments:
|
||||||
|
|
||||||
|
``` clojure
|
||||||
|
{"name" "pod.lispyclouds.another-deferred-ns"
|
||||||
|
"vars"
|
||||||
|
[{"name" "myfunc"
|
||||||
|
"code" "(require '[pod.lispyclouds.deferred-ns :as dns])
|
||||||
|
(defn my-func [] (dns/x))"}]}
|
||||||
|
```
|
||||||
|
|
||||||
#### Async
|
#### Async
|
||||||
|
|
||||||
Asynchronous functions can be implemented using callbacks.
|
Asynchronous functions can be implemented using callbacks.
|
||||||
|
|
|
||||||
|
|
@ -189,8 +189,8 @@
|
||||||
name-sym (symbol name-str)
|
name-sym (symbol name-str)
|
||||||
vars (get namespace "vars")
|
vars (get namespace "vars")
|
||||||
vars (bencode->vars pod name-str vars)
|
vars (bencode->vars pod name-str vars)
|
||||||
lazy? (some-> namespace (get-maybe-string "lazy") (= "true"))]
|
defer? (some-> namespace (get-maybe-string "defer") (= "true"))]
|
||||||
[name-sym vars lazy?]))
|
[name-sym vars defer?]))
|
||||||
|
|
||||||
(defn load-pod
|
(defn load-pod
|
||||||
([pod-spec] (load-pod pod-spec nil))
|
([pod-spec] (load-pod pod-spec nil))
|
||||||
|
|
|
||||||
|
|
@ -42,16 +42,14 @@
|
||||||
(intern
|
(intern
|
||||||
(create-ns (symbol (namespace sym)))
|
(create-ns (symbol (namespace sym)))
|
||||||
(symbol (name sym)))))})
|
(symbol (name sym)))))})
|
||||||
namespaces (:namespaces pod)
|
namespaces (:namespaces pod)]
|
||||||
load? (contains? (:ops pod) :load-ns)]
|
(swap! namespaces-to-load
|
||||||
(when load?
|
merge
|
||||||
(swap! namespaces-to-load
|
(into {}
|
||||||
merge
|
(keep (fn [[ns-name _ defer?]]
|
||||||
(into {}
|
(when defer?
|
||||||
(keep (fn [[ns-name _ lazy?]]
|
[ns-name pod]))
|
||||||
(when lazy?
|
namespaces)))
|
||||||
[ns-name pod]))
|
|
||||||
namespaces))))
|
|
||||||
(doseq [[ns-sym vars lazy?] namespaces
|
(doseq [[ns-sym vars lazy?] namespaces
|
||||||
:when (not lazy?)]
|
:when (not lazy?)]
|
||||||
(process-namespace {:name ns-sym :vars vars}))
|
(process-namespace {:name ns-sym :vars vars}))
|
||||||
|
|
|
||||||
|
|
@ -40,12 +40,10 @@
|
||||||
v)
|
v)
|
||||||
v))))}))
|
v))))}))
|
||||||
namespaces (:namespaces pod)
|
namespaces (:namespaces pod)
|
||||||
load? (contains? (:ops pod) :load-ns)
|
namespaces-to-load (set (keep (fn [[ns-name _ defer?]]
|
||||||
namespaces-to-load (when load?
|
(when defer?
|
||||||
(set (keep (fn [[ns-name _ lazy?]]
|
ns-name))
|
||||||
(when lazy?
|
namespaces))]
|
||||||
ns-name))
|
|
||||||
namespaces)))]
|
|
||||||
(when (seq namespaces-to-load)
|
(when (seq namespaces-to-load)
|
||||||
(let [load-fn (fn load-fn [{:keys [:namespace]}]
|
(let [load-fn (fn load-fn [{:keys [:namespace]}]
|
||||||
(when (contains? namespaces-to-load namespace)
|
(when (contains? namespaces-to-load namespace)
|
||||||
|
|
|
||||||
|
|
@ -82,11 +82,10 @@
|
||||||
"code" "(defn read-other-tag [x] [x x])"}]
|
"code" "(defn read-other-tag [x] [x x])"}]
|
||||||
dependents)}
|
dependents)}
|
||||||
{"name" "pod.test-pod.loaded"
|
{"name" "pod.test-pod.loaded"
|
||||||
"lazy" "true"}
|
"defer" "true"}
|
||||||
{"name" "pod.test-pod.loaded2"
|
{"name" "pod.test-pod.loaded2"
|
||||||
"lazy" "true"}]
|
"defer" "true"}]
|
||||||
"ops" {"shutdown" {}
|
"ops" {"shutdown" {}}})
|
||||||
"load-ns" {}}})
|
|
||||||
(recur))
|
(recur))
|
||||||
:invoke (let [var (-> (get message "var")
|
:invoke (let [var (-> (get message "var")
|
||||||
read-string
|
read-string
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue