(ns darkleaf.di.tutorial.c-stop-test
(:require
[clojure.test :as t]
[darkleaf.di.core :as di]))
To stop a component, you should teach DI how to do it.
Use ::di/stop to define a stop function.
(defn root
{::di/stop #(reset! % true)}
[{::keys [*stopped?]}]
*stopped?)
(t/deftest stop-test
(let [*stopped? (atom false)]
(with-open [root (di/start `root {::*stopped? *stopped?})]
(t/is (= false @@root)))
(t/is @*stopped?)))
In most cases, a component will be a Java class.
To prevent reflection calls use memfn
(defn- connection-manager
{::di/stop (memfn ^AutoCloseable close)}
[{max-conn :env.long/CONNECTION_MANAGER_MAX_CONN
:or {max-conn 50}}]
(ConnectionManager. max-conn))
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |