On Mon, Jan 24, 2011 at 11:23 PM, HiHeelHottie <hiheelhot...@gmail.com> wrote:
>
> user> (use '[clojure.contrib.http.agent :as ha])
> WARNING: bytes already refers to: #'clojure.core/bytes in namespace:
> user, being replaced by: #'clojure.contrib.http.agent/bytes
> nil
> user> (string (http-agent "http://url.that.doesnt.exist.com";))
>
> This will block indefinitely since the url does not exist.
>
> user> (def a (http-agent "http://url.that.doesnt.exist.com";))
> #'user/a
> user> (agent-error a)
> #<UnknownHostException java.net.UnknownHostException:
> url.that.doesnt.exist.com>
> user> (ha/done? a)
> false
>
> Is there a way to get http-agent to throw an exception on string?
> I've tried :connect-timeout, but to no avail since it blocks
> indefinitely.
>
> (string (http-agent "http://url.that.doesnt.exist.com"; :connect-
> timeout 10))

The library you're using may be based on the older agent behavior,
where derefing an agent that had errors would throw an exception.

The library probably should be modified to explicitly check the agent
for errors when dereferencing it. (if-let [e (agent-error a)] (throw
e)) is an expression that will throw a's error if it has one; that way
the thrown exception is the same one that the agent itself caught, so
your (string ...) would throw an UnknownHostException in this case.

The library's maintainer can define something like

(defn tderef [agt]
  (if-let [e (agent-error agt)]
    (throw e)
    @agt))

and use (tferef agt) in place of (deref agt) or @agt in appropriate places.

-- 
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

Reply via email to