Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use more complete examples
  • Loading branch information
kraih committed Nov 4, 2017
1 parent e0c08e0 commit 540f7d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/Mojo/IOLoop.pm
Expand Up @@ -415,7 +415,9 @@ Callbacks will be passed along to L<Mojo::IOLoop::Delay/"steps">.
my $promise = Mojo::IOLoop->delay;
$ua->get(@_ => sub {
my ($ua, $tx) = @_;
$promise->resolve($tx);
my $err = $tx->error;
$promise->resolve($tx) if !$err || $err->{code};
$promise->reject($err->{message});
});
return $promise;
}
Expand Down
7 changes: 5 additions & 2 deletions lib/Mojo/Promise.pm
Expand Up @@ -128,14 +128,17 @@ Mojo::Promise - Promises/A+
=head1 SYNOPSIS
use Mojo::Promise;
use Mojo::UserAgent;
# Wrap continuation-passing style APIs with promises
my $ua = Mojo::UserAgent->new;
sub get {
my $promise = Mojo::Promise->new;
$ua->get(@_ => sub {
my ($ua, $tx) = @_;
$promise->resolve($tx);
my $err = $tx->error;
$promise->resolve($tx) if !$err || $err->{code};
$promise->reject($err->{message});
});
return $promise;
}
Expand All @@ -155,7 +158,7 @@ L<Mojo::Promise> implements the following attributes.
=head2 ioloop
my $loop = $promise->ioloop;
$promise = $promise->ioloop(Mojo::IOLoop->new);
$promise = $promise->ioloop(Mojo::IOLoop->new);
Event loop object to control, defaults to the global L<Mojo::IOLoop> singleton.
Expand Down

0 comments on commit 540f7d3

Please sign in to comment.