Skip to content

Commit

Permalink
better recipe for exceptions in events
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 10, 2014
1 parent 524bc73 commit 11f2cf5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -515,20 +515,24 @@ created at startup time.

app->start;

Just remember that all events are processed cooperatively, so your callbacks
shouldn't block for too long.

=head2 Exceptions in events

Since timers and other event watchers are independent from applications,
errors can't get logged automatically, you can change that by subscribing to
the event L<Mojo::Reactor/"error">.
Since timers and other non-blocking operations are running solely in the event
loop, outside of the application, errors in callbacks can't get caught and
logged automatically, you can change that by subscribing to the event
L<Mojo::Reactor/"error">.

# Forward error messages to the application log
Mojo::IOLoop->singleton->reactor->on(error => sub {
my ($reactor, $err) = @_;
app->log->error($err);
});

Just remember that all events are processed cooperatively, so your callbacks
shouldn't block for too long.
A default subscriber that prints all errors to C<STDERR> will usually be added
by L<Mojo::IOLoop> as a fallback.

=head2 WebSocket web service

Expand Down

0 comments on commit 11f2cf5

Please sign in to comment.