Skip to content

Commit

Permalink
document how to use catch with delays
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 25, 2014
1 parent d9896cb commit 9094e57
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

5.0 2014-05-24
5.0 2014-05-25
- Code name "Tiger Face", this is a major release.
- Changed heuristics for number detection in Mojo::JSON to better line up
with user expectations.
Expand Down
15 changes: 15 additions & 0 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -479,6 +479,21 @@ L<Mojo::IOLoop::Delay/"steps">.
);
$delay->wait unless Mojo::IOLoop->is_running;
# Handle exceptions in all steps
my $delay = Mojo::IOLoop->delay(
sub {
my $delay = shift;
die 'Intentional error!';
},
sub {
my ($delay, @args) = @_;
say 'Never actually reached.';ø
}
)->catch(sub {
my ($delay, $err) = @_;
say "Something went wrong: $err";
});
=head2 is_running
my $bool = Mojo::IOLoop->is_running;
Expand Down
16 changes: 16 additions & 0 deletions lib/Mojo/IOLoop/Delay.pm
Expand Up @@ -117,6 +117,22 @@ Mojo::IOLoop::Delay - Manage callbacks and control the flow of events
);
$delay->wait unless Mojo::IOLoop->is_running;
# Handle exceptions in all steps
my $delay = Mojo::IOLoop::Delay->new;
$delay->steps(
sub {
my $delay = shift;
die 'Intentional error!';
},
sub {
my ($delay, @args) = @_;
say 'Never actually reached.';
}
)->catch(sub {
my ($delay, $err) = @_;
say "Something went wrong: $err";
});
=head1 DESCRIPTION
L<Mojo::IOLoop::Delay> manages callbacks and controls the flow of events for
Expand Down

0 comments on commit 9094e57

Please sign in to comment.