best way to design user-defined hook system (handling async errors)
Lee Aylward
laylward at gmail.com
Sat Jan 26 23:55:22 CET 2013
Hi Marc,
I'm a big fan of AnyEvent, and have built a small web-scraping framework with it (http://noembed.com). Much of the app is defined as separate components that work as plugins; registering URL patterns that they can handle. If a component matches, it is run with a callback to call when complete.
The problem with this design is that there is very little that can be done if a component dies inside of one of it's own asynchronous callbacks (e.g. AE::HTTP, AE::timer). Here is an example of the problem I'm running into:
https://gist.github.com/4645022
I realize this could be somewhat mitigated by passing in a Condvar and requiring the component to catch any errors and then call $cv->croak.
Is there *any* way to handle errors like the one linked above, without requiring the hook to eval everything, and use a Condvar? I'd really like to keep the hook definitions as simple as possible, requiring no knowledge of the internals of the app.
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.
Thanks for any insights!
--
Lee Aylward
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/anyevent/attachments/20130126/58cc6627/attachment.html>
More information about the anyevent
mailing list