I have discovered that, in the case of an agent action exception, the
behavior of agent await depends on timing:
- If your await happens to execute after the action is completed, it will
happily throw an exception that the agent is in a failed state.
- If your await happens to execute before the action is completed, it will
dangerously block. (!!!)
Shouldn't await behave the same in both cases?
Code example:
(defn await-agent-after-fail []
(let [agt (agent nil)]
(send-off agt (fn [_]
(println "Agent throws exception now")
(throw (ex-info "fail!" {}))))
(Thread/sleep 1000)
(println "Agent is awaited now...")
(println "Await timed out?" (not (await-for 10000 agt)))))
(comment
(await-agent-after-fail))
(defn await-agent-before-fail []
(let [agt (agent nil)]
(send-off agt (fn [_]
(Thread/sleep 1000)
(println "Agent throws exception now")
(throw (ex-info "fail!" {}))))
(println "Agent is awaited now...")
(println "Await timed out?" (not (await-for 10000 agt)))))
(comment
(await-agent-before-fail))
--
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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/clojure/9cf9a5c3-1dcb-4d4a-b180-a2cd6568853do%40googlegroups.com.