On Sat, Jan 26, 2013 at 04:55:22PM -0600, Lee Aylward <[email protected]> 
wrote:
> Is there *any* way to handle errors like the one linked above, without 
> requiring the hook to eval everything, and use a Condvar?

Hi - I am not exactly what you are after, but AnyEvent isn't really
"special", that is, any kind of error handling you want to use still works
with AnyEvent (modulo the event loop in use).

If I get you right, you wonder how to communicate errors to callbacks.

I would say that depends very much on the application in question. For
example, AnyEvent::Socket::tcp_connect or the AnyEvent::IO functions call
the callback without any arguments.

Other callbacks might be called with undef. AnyEvent::HTTP calls the
callback with "undef" for the body, and a set of headers which indicate
which error happened.

AnyEvent::Handle has a separate callback for errors.

I would expect that there is always a natural way to communicate errors,
one that creates least complications in typical use cases.

If you are concerned about your callback calling die without being able to
prevent it, then indeed, you need to use eval.

For this case, you could create a wrapper that does what is needed, e.g.

   AE::timer 5, 0, mysub { ... } $error_cb;

Or whatever is appropriate.

> I took a brief look at doing "local $SIG{__DIE__} = sub { $cv->send };" 
> before calling the hook, but it appears that the local die handler is no 
> longer defined when the hook's timer callback is called.

Almost all uses of $SIG{__DIE__} are broken, especially simple ones like
in your example. Writing a proper __DIE__ handler is very complicated - my
advice would be to avoid __DIE__ whenever possible.

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      [email protected]
      -=====/_/_//_/\_,_/ /_/\_\

_______________________________________________
anyevent mailing list
[email protected]
http://lists.schmorp.de/mailman/listinfo/anyevent

Reply via email to