This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # admin-announcements (24)
- # beginners (80)
- # cider (18)
- # cljs-dev (12)
- # clojure (94)
- # clojure-berlin (15)
- # clojure-dev (10)
- # clojure-gamedev (3)
- # clojure-italy (38)
- # clojure-japan (4)
- # clojure-russia (109)
- # clojure-sg (1)
- # clojurescript (161)
- # code-reviews (29)
- # core-async (17)
- # datomic (20)
- # editors (14)
- # instaparse (17)
- # ldnclj (9)
- # off-topic (9)
- # om (2)
- # onyx (2)
- # re-frame (11)
- # reagent (46)
Is there a way to get something like a promise in core.async? When w client connects I establish an initial connection that will be used by subsequent queries. I want to be able to park my go block until the db connection is established.
@danielcompton: could use a channel with a single value
@alejandro: but that channel will be exhausted after the first query, how do I get the connection for subsequent queries?
gotcha, may be easiest to use a real promise that is delivered on by a callback from a take! operation?
or wait for http://dev.clojure.org/jira/browse/ASYNC-103 to be merged 😉
@nullptr: I only want to make the connection once
Looks like ASYNC-103 is what I want
seems reasonable -- though keep in mind that you can put the same connection on multiple chans
@nullptr: I am going to make a query an unbounded number of times, I'm sure there's a way I could do this, but it seems messy
You can always just infinite loop:
(defn <get-conn [params] (let [out-ch (chan)] (go-loop [conn nil] (if conn (do (>! out-ch conn) (recur conn)) (recur (make-db-connection! params)))) out-ch))
@erik_price: I want one db-connection shared, but I see what you’re saying about the pattern
this does that, for better or for worse
@erik_price: oh, I didn’t read that correctly, I thought it recurred with a new db each time
could be kinda nice to add checks there if the connection is closed too, e.t.c. Thanks!
Sure. This can get even bigger if you want. You could even pass in a control channel that would let a caller shut down the current database connection (you’d have to
alts on that vs the normal path) if you needed teardown functionality.