make waiting for threads to exit behaviour the default
switching the optional boolean arg to now be used to decide whether to skip waiting for the threads or not (default not)
This commit is contained in:
parent
3e28d19474
commit
4a6794ff73
|
@ -304,7 +304,7 @@
|
||||||
|
|
||||||
(defn stop-update-watcher!
|
(defn stop-update-watcher!
|
||||||
"Stops threads for the views refresh watcher and worker threads."
|
"Stops threads for the views refresh watcher and worker threads."
|
||||||
[^Atom view-system & [wait-for-threads?]]
|
[^Atom view-system & [dont-wait-for-threads?]]
|
||||||
(trace "stopping refresh watcher and workers")
|
(trace "stopping refresh watcher and workers")
|
||||||
(let [worker-threads (:workers @view-system)
|
(let [worker-threads (:workers @view-system)
|
||||||
watcher-thread (:refresh-watcher @view-system)
|
watcher-thread (:refresh-watcher @view-system)
|
||||||
|
@ -316,7 +316,7 @@
|
||||||
:stop-workers? true)
|
:stop-workers? true)
|
||||||
(doseq [^Thread t threads]
|
(doseq [^Thread t threads]
|
||||||
(.interrupt t))
|
(.interrupt t))
|
||||||
(if wait-for-threads?
|
(if-not dont-wait-for-threads?
|
||||||
(doseq [^Thread t threads]
|
(doseq [^Thread t threads]
|
||||||
(.join t)))
|
(.join t)))
|
||||||
(swap! view-system assoc
|
(swap! view-system assoc
|
||||||
|
@ -355,12 +355,12 @@
|
||||||
|
|
||||||
(defn stop-logger!
|
(defn stop-logger!
|
||||||
"Stops the logger thread."
|
"Stops the logger thread."
|
||||||
[^Atom view-system & [wait-for-thread?]]
|
[^Atom view-system & [dont-wait-for-thread?]]
|
||||||
(trace "stopping logger")
|
(trace "stopping logger")
|
||||||
(let [^Thread logger-thread (get-in @view-system [:statistics :logger])]
|
(let [^Thread logger-thread (get-in @view-system [:statistics :logger])]
|
||||||
(swap! view-system assoc-in [:statistics :stop?] true)
|
(swap! view-system assoc-in [:statistics :stop?] true)
|
||||||
(if logger-thread (.interrupt logger-thread))
|
(if logger-thread (.interrupt logger-thread))
|
||||||
(if wait-for-thread? (.join logger-thread))
|
(if-not dont-wait-for-thread? (.join logger-thread))
|
||||||
(swap! view-system assoc-in [:statistics :logger] nil)))
|
(swap! view-system assoc-in [:statistics :logger] nil)))
|
||||||
|
|
||||||
(defn hint
|
(defn hint
|
||||||
|
@ -486,10 +486,10 @@
|
||||||
(defn shutdown!
|
(defn shutdown!
|
||||||
"Shuts the view system down, terminating all worker threads and clearing
|
"Shuts the view system down, terminating all worker threads and clearing
|
||||||
all view subscriptions and data."
|
all view subscriptions and data."
|
||||||
[^Atom view-system & [wait-for-threads?]]
|
[^Atom view-system & [dont-wait-for-threads?]]
|
||||||
(trace "shutting down views sytem")
|
(trace "shutting down views sytem")
|
||||||
(stop-update-watcher! view-system wait-for-threads?)
|
(stop-update-watcher! view-system dont-wait-for-threads?)
|
||||||
(if (:logging? @view-system)
|
(if (:logging? @view-system)
|
||||||
(stop-logger! view-system wait-for-threads?))
|
(stop-logger! view-system dont-wait-for-threads?))
|
||||||
(reset! view-system {})
|
(reset! view-system {})
|
||||||
view-system)
|
view-system)
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
(doseq [^Thread t workers]
|
(doseq [^Thread t workers]
|
||||||
(is (.isAlive t)))
|
(is (.isAlive t)))
|
||||||
; 2. shutdown views (and wait for all threads to also finish)
|
; 2. shutdown views (and wait for all threads to also finish)
|
||||||
(shutdown! test-views-system true)
|
(shutdown! test-views-system)
|
||||||
(is (empty? @test-views-system))
|
(is (empty? @test-views-system))
|
||||||
(is (not (.isAlive ^Thread refresh-watcher)))
|
(is (not (.isAlive ^Thread refresh-watcher)))
|
||||||
(doseq [^Thread t workers]
|
(doseq [^Thread t workers]
|
||||||
|
@ -56,7 +56,7 @@
|
||||||
(let [logger-thread (get-in @test-views-system [:statistics :logger])]
|
(let [logger-thread (get-in @test-views-system [:statistics :logger])]
|
||||||
(is (.isAlive ^Thread logger-thread))
|
(is (.isAlive ^Thread logger-thread))
|
||||||
; 2. shutdown views
|
; 2. shutdown views
|
||||||
(shutdown! test-views-system true)
|
(shutdown! test-views-system)
|
||||||
(is (nil? (get-in @test-views-system [:statistics :logger])))
|
(is (nil? (get-in @test-views-system [:statistics :logger])))
|
||||||
(is (not (.isAlive ^Thread logger-thread))))))
|
(is (not (.isAlive ^Thread logger-thread))))))
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@
|
||||||
(contains-view? test-views-system :one)
|
(contains-view? test-views-system :one)
|
||||||
(contains-view? test-views-system :two)))
|
(contains-view? test-views-system :two)))
|
||||||
; 3. shutdown views
|
; 3. shutdown views
|
||||||
(shutdown! test-views-system true)))
|
(shutdown! test-views-system)))
|
||||||
|
|
||||||
(deftest can-replace-views-after-init
|
(deftest can-replace-views-after-init
|
||||||
(let [options test-options
|
(let [options test-options
|
||||||
|
@ -95,4 +95,4 @@
|
||||||
(contains-view? test-views-system :baz)))
|
(contains-view? test-views-system :baz)))
|
||||||
(is (= replacement-view (get-in @test-views-system [:views :foo])))
|
(is (= replacement-view (get-in @test-views-system [:views :foo])))
|
||||||
; 3. shutdown views
|
; 3. shutdown views
|
||||||
(shutdown! test-views-system true)))
|
(shutdown! test-views-system)))
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
(reset! test-views-system {})
|
(reset! test-views-system {})
|
||||||
(f)
|
(f)
|
||||||
(if (seq @test-views-system)
|
(if (seq @test-views-system)
|
||||||
(shutdown! test-views-system true)))
|
(shutdown! test-views-system)))
|
||||||
|
|
||||||
(def memory-view-hint-type :memory-db)
|
(def memory-view-hint-type :memory-db)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue