Skip to content

Commit 49b528f

Browse files
committed
fix ensure-orgx-watch!-test failing
1 parent fc3fd64 commit 49b528f

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

src/net/coruscation/cerulean/server/server.clj

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,32 @@
6868
(let [service (watch-service/watch blog-dir)
6969
[resp _] service]
7070
{: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!)
8189

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))}))))
8897

8998
(defn stop-orgx-watch! [blog-dir]
9099
(let [[_ cancel] (:service (ensure-orgx-watch! blog-dir))]

0 commit comments

Comments
 (0)