Skip to content

Commit

Permalink
more complete promise example
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 4, 2017
1 parent b09d55a commit e6df642
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/Mojo/Promise.pm
Expand Up @@ -142,9 +142,17 @@ Mojo::Promise - Promises/A+
});
return $promise;
}
# Synchronize multiple non-blocking operations
my $mojo = get('http://mojolicious.org');
my $cpan = get('http://metacpan.org');
Mojo::Promise->race($mojo, $cpan)->then(sub { say shift->req->url })->wait;
Mojo::Promise->race($mojo, $cpan)->then(sub {
my $tx = shift;
say $tx->req->url, ' won!';
})->catch(sub {
my $err = shift;
warn "Something went wrong: $err";
})->wait;
=head1 DESCRIPTION
Expand Down

0 comments on commit e6df642

Please sign in to comment.