|
68 | 68 | (let [service (watch-service/watch blog-dir) |
69 | 69 | [resp _] service] |
70 | 70 | {:service service |
71 | | - :future (future |
72 | | - (loop [event (a/<!! resp)] |
73 | | - (when (not (nil? event)) |
74 | | - (try |
75 | | - (when (and (instance? Path (:path event)) |
76 | | - (.endsWith (.toString (:path event)) ".org")) |
77 | | - (generate-all-orgx!) |
78 | | - (cond (= (:kind event) |
79 | | - :entry-create) |
80 | | - (api/watch-compile-all!) |
| 71 | + :thread |
| 72 | + ;; Do not use a threadpool (i.e. future) |
| 73 | + ;; |
| 74 | + ;; The caller should ensure its current ClassLoader is a DynamicClassLoader |
| 75 | + ;; If we use a threadpool, the following code may executed in an preexisting thread, |
| 76 | + ;; and its ContextClassLoader will not inherit the caller's ClassLoader. |
| 77 | + ;; It is mostly a problem when doing unit test though. |
| 78 | + (doto (Thread/new |
| 79 | + (bound-fn [] |
| 80 | + (loop [event (a/<!! resp)] |
| 81 | + (when (not (nil? event)) |
| 82 | + (try |
| 83 | + (when (and (instance? Path (:path event)) |
| 84 | + (.endsWith (.toString (:path event)) ".org")) |
| 85 | + (generate-all-orgx!) |
| 86 | + (cond (= (:kind event) |
| 87 | + :entry-create) |
| 88 | + (api/watch-compile-all!) |
81 | 89 |
|
82 | | - ;; necessary for some unknown reason |
83 | | - *in-cli?* |
84 | | - (api/watch-compile! :app))) |
85 | | - (catch Throwable t |
86 | | - (logging/warn "Generated orgx file failed" t))) |
87 | | - (recur (a/<!! resp)))))})))) |
| 90 | + ;; necessary for some unknown reason |
| 91 | + *in-cli?* |
| 92 | + (api/watch-compile! :app))) |
| 93 | + (catch Throwable t |
| 94 | + (logging/warn "Generated orgx file failed" t))) |
| 95 | + (recur (a/<!! resp)))))) |
| 96 | + (.start))})))) |
88 | 97 |
|
89 | 98 | (defn stop-orgx-watch! [blog-dir] |
90 | 99 | (let [[_ cancel] (:service (ensure-orgx-watch! blog-dir))] |
|
0 commit comments