Looks like refs are not particularly the best tool for the job in this case - those values aren't going to change a lot right? And they could be expressed as a single hashmap - removing the needs for transactionality.
Answering to your question, it is impossible to reach the (when...) without the two refs being succesfully set: dosync blocks, and throws an exception if something goes wrong. On Wednesday, February 27, 2013 12:38:56 AM UTC+1, larry google groups wrote: > > I would like to connect to MongoDb with the following code, but I am > worried about the side-effecting code that comes right after the > dosync: > > > (def which-database-to-use (ref false)) > (def which-collection-to-use (ref false)) > > (defn connect-to-server [] > (mg/connect!)) > > (defn set-database-to-use [] > (mg/set-db! (mg/get-db @which-database-to-use))) > > (defn establish-database-connection [database-name-as-string > collection-name-as-string] > (dosync > (ref-set which-database-to-use database-name-as-string) > (ref-set which-collection-to-use collection-name-as-string)) > (when @which-database-to-use > (connect-to-server) > (set-database-to-use))) > > > Is there a risk that set-database-to-use will be called before the > dosync is finished? > > > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.