Closed lkrubner closed 10 years ago
I guess this would happen if there had already been an exception on that thread, which had gone uncaught?
That's definitely plausible. I don't see anything wrong with your usage of the library. Does it work when used within the same namespace?
Strangely, if I do this:
(ns loupi.persistence-queue
(:require
[loupi.persistence :as persistence]
[slingshot.slingshot :as slingshot]
[lamina.core :as lamina]
[dire.core :as dr]))
(def ^:private persistence-channel (lamina/channel))
(defn persist-this-item [context-wrapper-for-database-call]
(lamina/enqueue persistence-channel
(fn []
(persistence/make-consistent context-wrapper-for-database-call))))
(dr/with-eager-pre-hook! #'persist-this-item
"An optional docstring."
(fn [a] (println "Logging something before preconditions are evaluated." )
(println (str a))))
Then the "Logging something before preconditions are evaluated." shows up in my terminal. But if move the pre-hook to its own namespace:
(ns loupi.supervisor
(:require
[loupi.perpetual :as perpetual]
[loupi.startup :as startup]
[loupi.server :as server]
[loupi.dates :as dt]
[clojure.string :as st]
[clj-stacktrace.core :as stack]
[dire.core :as dire]
[taoensso.timbre :as timbre]))
(dire/with-eager-pre-hook! #'loupi.persistence-queue/persist-this-item
"An optional docstring."
(fn [a b] (println "Logging something before preconditions are evaluated.")))
Then this does not appear in my terminal output: "Logging something before preconditions are evaluated.")
And it makes no difference if I use :use to include the namespace:
(ns loupi.supervisor
(:require
[loupi.perpetual :as perpetual]
[loupi.startup :as startup]
[loupi.server :as server]
[loupi.dates :as dt]
[clojure.string :as st]
[clj-stacktrace.core :as stack]
[dire.core :as dire]
[taoensso.timbre :as timbre]
(:use
[loupi.persistence-queue])))
(dire/with-eager-pre-hook! #'loupi.persistence-queue/persist-this-item
"An optional docstring."
(fn [a b] (println "Logging something before preconditions are evaluated.")))
That's really weird. Are you sure the namespace containing the hooks is getting required before the function call?
Damn, that was obvious. I'd changed the order of things being required, and I'd left out a crucial one.
No problem, happens all the time! Closing unless anything else arises.
I have an odd problem. I have hooked to vars in other namespaces before, but now I seem to be not matching, perhaps because of my use of Slingshot.
I have namespace which starts as:
And then I have another namespace where I want to add an eager pre-hook. I tried linking to the other var in these ways:
and I also tried:
or just:
None of these seem to work.
This line runs and prints to stdout so I can see it in the terminal:
but I can not get the pre-hook to work. Any suggestions?
If I look at RobertHooke:
https://github.com/technomancy/robert-hooke/
They offer this example:
(add-hook #'some.ns/target-var #'hook-function)
And I feel like what I'm doing is similar, so I am unsure what I am doing wrong.