Re: core.async: async java.jdbc

2013-08-01 Thread Alice
What if I want to run a select query in the middle of a transaction? On Thursday, August 1, 2013 3:33:29 AM UTC+9, tbc++ wrote: DB work is a IO operation, and IO shouldn't be done inside a go block (go blocks use limited thread pools). So what about something like this? (defn handle-db

Re: core.async: async java.jdbc

2013-08-01 Thread Jonah Benton
These are interesting code listings and questions, but they conflate the syntactic detail that core.async's go is implemented as a macro, with the semantic intention to support designs around lightweight data flow between independent code blocks. It might be of value to check out Go, the

core.async: async java.jdbc

2013-07-31 Thread Alice
(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

Re: core.async: async java.jdbc

2013-07-31 Thread Sean Corfield
On Wed, Jul 31, 2013 at 10:29 AM, Alice dofflt...@gmail.com wrote: (go (jdbc/db-transaction [t-con db-spec] (! (insert-async! t-con :fruit {:name apple} Does this work: (jdbc/db-transaction [t-con db-spec] (go (! (insert-async! t-con :fruit {:name apple} -- Sean A

Re: core.async: async java.jdbc

2013-07-31 Thread Alice
It doesn't produce a compile time error but I think it's not the correct code because the transaction can be committed while insert-async! is still executing. On Thursday, August 1, 2013 2:46:29 AM UTC+9, Sean Corfield wrote: On Wed, Jul 31, 2013 at 10:29 AM, Alice doff...@gmail.com

Re: core.async: async java.jdbc

2013-07-31 Thread Timothy Baldridge
Why not use !! ? Timothy On Wed, Jul 31, 2013 at 11:58 AM, Alice dofflt...@gmail.com wrote: It doesn't produce a compile time error but I think it's not the correct code because the transaction can be committed while insert-async! is still executing. On Thursday, August 1, 2013 2:46:29 AM

Re: core.async: async java.jdbc

2013-07-31 Thread Alice
I have an async http handler and I don't want it to consume a thread. On Thursday, August 1, 2013 3:16:52 AM UTC+9, tbc++ wrote: Why not use !! ? Timothy On Wed, Jul 31, 2013 at 11:58 AM, Alice doff...@gmail.com javascript:wrote: It doesn't produce a compile time error but I think it's

Re: core.async: async java.jdbc

2013-07-31 Thread Timothy Baldridge
DB work is a IO operation, and IO shouldn't be done inside a go block (go blocks use limited thread pools). So what about something like this? (defn handle-db [chan] (thread (while true (let [[data result] (! c)] (run-db-transaction-as-normal data) (! result

Re: core.async: async java.jdbc

2013-07-31 Thread Alice
(defn insert-async! [ args] (db-thread (try (apply jdbc/insert! args) (catch Throwable t t db-thread is a macro that runs the body in a fixed thread pool, so IO isn't done inside a go block. On Thursday, August 1, 2013 3:33:29 AM UTC+9, tbc++ wrote: DB work is

Re: core.async: async java.jdbc

2013-07-31 Thread Sean Corfield
On Wed, Jul 31, 2013 at 10:58 AM, Alice dofflt...@gmail.com wrote: It doesn't produce a compile time error but I think it's not the correct code because the transaction can be committed while insert-async! is still executing. Right. I was just showing how to avoid the compile error (because