Re: Inadequate behavior of agent await?

2020-06-10 Thread Sean Corfield
If you provide an error handler on the agent -- or just specify the error
mode as :continue -- it does not hang. That makes me think that what you're
seeing is "expected behavior" although it does seem a bit strange...?

On Wed, Jun 10, 2020 at 1:49 AM Ernesto Garcia  wrote:

> 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 1 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 1 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 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/clojure/9cf9a5c3-1dcb-4d4a-b180-a2cd6568853do%40googlegroups.com
> 
> .
>


-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- https://corfield.org/
World Singles Networks, LLC. -- https://worldsinglesnetworks.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/CAD4thx_jjdO29_rLrDZmxdeot0VcQksa4RjDBm10NGB3SmwMHA%40mail.gmail.com.


Inadequate behavior of agent await?

2020-06-10 Thread Sam Griffith
You may want to ask this on ClojureVerse or on the official Q/A site at 
https://ask.clojure.org/index.php/

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/bda66482-76e3-49ee-8e2c-bffd1635bc15o%40googlegroups.com.


Inadequate behavior of agent await?

2020-06-10 Thread Ernesto Garcia
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 1 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 1 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 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/9cf9a5c3-1dcb-4d4a-b180-a2cd6568853do%40googlegroups.com.