Back
halt! (clj)
(source)function
(halt! system)
(halt! system keys)
Halt a system map by applying halt-key! in reverse dependency order.
Examples
integrant
(ns integrant.core-test
(:require #?(:clj [clojure.test :refer [are deftest is testing]]
:cljs [cljs.test :refer-macros [are deftest is testing]])
[integrant.core :as ig]
[weavejester.dependency :as dep]))
(deftest halt-test
(testing "without keys"
(reset! log [])
(let [m (ig/init {::a (ig/ref ::b), ::b 1})]
(ig/halt! m)
(is (= @log [[:init ::b 1]
[:init ::a [1]]
[:halt ::a [[1]]]
[:halt ::b [1]]]))))
(testing "with keys"
(reset! log [])
(let [m (ig/init {::a (ig/ref ::b), ::b (ig/ref ::c), ::c 1})]
(ig/halt! m [::a])
(is (= @log [[:init ::c 1]
[:init ::b [1]]
[:init ::a [[1]]]
[:halt ::a [[[1]]]]]))
(reset! log [])
(ig/halt! m [::c])
(is (= @log [[:halt ::a [[[1]]]]
[:halt ::b [[1]]]
[:halt ::c [1]]]))))
(testing "with partial system"
(reset! log [])
(let [m (ig/init {::a 1, ::b (ig/ref ::a)} [::a])]
(ig/halt! m)
(is (= @log [[:init ::a 1]
[:halt ::a [1]]]))))
(testing "with inherited keys"
(reset! log [])
(let [m (ig/init {::a (ig/ref ::p), ::p 1} [::a])]
(ig/halt! m [::pp])
(is (= @log [[:init ::p 1]
[:init ::a [1]]
[:halt ::a [[1]]]
[:halt ::p [1]]]))))
(testing "with composite keys"
(reset! log [])
(let [m (ig/init {::a (ig/ref ::b), [::x ::b] 1})]
(ig/halt! m)
(is (= @log [[:init [::x ::b] 1]
[:init ::a :x]
[:halt ::a [:x]]
[:halt [::x ::b] :x]])))))
(testing "exception when running"
(let [system (ig/init {::a 1
::error-halt (ig/ref ::a)
::b (ig/ref ::error-halt)
::c (ig/ref ::b)})
ex (try (ig/halt! system)
(catch #?(:clj Throwable :cljs :default) t t))]
(is (some? ex))
(is (= (#?(:clj .getMessage :cljs ex-message) ex)
(str "Error on key " ::error-halt " when running system")))
(is (= (ex-data ex)
{:reason ::ig/run-threw-exception
:system {::a [1], ::error-halt [[1]]
::b [[[1]]], ::c [[[[1]]]]}
:completed-keys '(::c ::b)
:remaining-keys '(::a)
:function ig/halt-key!
:key ::error-halt
:value [[1]]}))
(let [cause (#?(:clj .getCause :cljs ex-cause) ex)]
(is (some? cause))
(is (= (#?(:clj .getMessage :cljs ex-message) cause) "Testing"))
(is (= (ex-data cause) {:reason ::test}))))))
samply/blaze
(ns blaze.scheduler-test
(:require
[blaze.executors :as ex]
[blaze.module.test-util :refer [with-system]]
[blaze.scheduler :as sched]
[blaze.scheduler-spec]
[blaze.test-util :as tu]
[clojure.spec.test.alpha :as st]
[clojure.test :as test :refer [deftest is testing]]
[integrant.core :as ig]
[java-time.api :as time]
[taoensso.timbre :as log]))
(ig/halt! system)
samply/blaze
(ns blaze.module.test-util
(:require
[integrant.core :as ig]))
(defmacro with-system
"Runs `body` inside a system that is initialized from `config`, bound to
`binding-form` and finally halted."
[[binding-form config] & body]
`(let [system# (ig/init ~config)]
(try
(let [~binding-form system#]
~@body)
(finally
(ig/halt! system#)))))
markbastian/partsbin
(ns partsbin.crux.api.core
(:require [partsbin.crux.api.alpha :as crux]
[crux.api :as crux-api]
[integrant.core :as ig]))
(ig/halt! system))
markbastian/partsbin
(ns partsbin.hawk.core.core
(:require [integrant.core :as ig]
[partsbin.hawk.core.alpha :as hawk]))
(comment
(def sys (ig/init config))
(ig/halt! sys))
markbastian/partsbin
(ns partsbin.etaoin.api.core
(:require [partsbin.etaoin.api.alpha :as webdriver]
[integrant.core :as ig]
[datascript.core :as d]))
(comment
(def sys (ig/init config))
(ig/halt! sys))