I want to execute a sequence of database queries (in order) and stop when
the first one returns a result.
I've set up things so that a "query" returns a channel that will be
populated with the result, and I set up the queries lazily using a for
comprehension.
A simplified illustrative example of all of this is below. Note that
async/to-chan should not even be called for the items beyond the one
containing "foo".
(async/<!! (let [chans (for [coll [[] [] ["foo"] [] ["bar"]]]
(async/to-chan coll))]
(async/go (loop [[ch & rest] chans]
(if-let [val (<! ch)]
val
(when rest
(recur rest)))))))
=> "foo"
This smells a lot like a core.async variant of some having behavior
analogous to the simpler example:
(some identity [nil nil "foo" nil "bar"])
=> "foo"
I'm curious if there already exists a core.async construct that either
directly or indirectly matches what I'm trying to do
I'd also accept advice that the entire approach is wrong. Lazily evaluating
queries (which cause database I/O only when are evaluated) could seem
reasonable in blocking / synchronous code, but perhaps there is a much
better way to achieve this in a style that is consistent with core.async.
--
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/d/optout.