(defonce ^ExecutorService db-thread-pool (Executors/newFixedThreadPool 8))
(defn db-thread-call
[f]
(let [c (chan 1)]
(.execute db-thread-pool
(fn []
(let [ret (try
(f)
(catch Throwable t
nil))]
(when-not (nil? ret)
(>!! c ret))
(close! c))))
c))
(defmacro db-thread
[& body]
`(db-thread-call (fn [] ~@body)))
(defn insert-async!
[& args]
(db-thread
(try
(apply jdbc/insert! args)
(catch Throwable t
t))))
(go
(jdbc/db-transaction [t-con db-spec]
(<! (insert-async! t-con :fruit {:name "apple"}))))
Exception in thread "async-dispatch-5" java.lang.AssertionError: Assert
failed: <! used not in (go ...) block
So, do we need a db-transaction that does all the work inside a macro
instead of wrapping the body into a function and passing it to another
function?
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.