Skip to content

Commit

Permalink
more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 26, 2017
1 parent dbf81f6 commit f64c0b4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/Mojo/IOLoop/Delay.pm
Expand Up @@ -426,12 +426,19 @@ L<Mojo::IOLoop::Delay> object resolving to the return value of the callback if
it is called, or to its original fulfillment value if the promise is instead
fulfilled.
# Pass along the rejection reason
$delay->catch(sub {
my @reason = @_;
warn "Something went wrong: $reason[0]";
return @reason;
});
# Change the rejection reason
$delay->catch(sub {
my @reason = @_;
return "This is bad: $reason[0]";
});
=head2 data
my $hash = $delay->data;
Expand All @@ -455,6 +462,7 @@ Appends a fulfillment and rejection handler to the promise, and returns a new
L<Mojo::IOLoop::Delay> object resolving to the original fulfillment value or
rejection reason.
# Do something on fulfillment and rejection
$delay->finally(sub {
my @value_or_reason = @_;
say "We are done!";
Expand Down Expand Up @@ -505,12 +513,15 @@ it will be rejected.
=head2 then
my $new = $delay->then(sub {...});
my $new = $delay->then(sub {...}, sub {...});
my $new = $delay->then(undef, sub {...});
Appends fulfillment and rejection handlers to the promise, and returns a new
L<Mojo::IOLoop::Delay> object resolving to the return value of the called
handler.
# Pass along the fulfillment value or rejection reason
$delay->then(sub {
my @value = @_;
say "The result is $value[0]";
Expand All @@ -522,6 +533,16 @@ handler.
return @reason;
});
# Change the fulfillment value or rejection reason
$delay->then(sub {
my @value = @_;
return "The result is $value[0]";
},
sub {
my @reason = @_;
return "Something went wrong: $reason[0]";
});
=head2 wait
$delay->wait;
Expand Down

0 comments on commit f64c0b4

Please sign in to comment.