I'm playing with Mojo::UserAgent and Mojo::Promise to run non-blocking calls to 3 services A, B, and C. The problem is it works fine when all the services connect/resolve, but if one of those, say, service C is unable to connect, the whole thing fail. Is there a way to capture all services (connect and Not-connect)? Any insight is greatly appreciated. Thanks!
my @urls = (
'https://hostA/serviceA', # ServcieA connects and returns some text
'https://hostB/serviceB', # ServiceB connects and returns some text
'https://hostC/serviceC', # ServiceC refuses to connect
);
my $ua = Mojo::UserAgent->new;
my @promises = map { $ua->get_p($_) } @urls;
Mojo::Promise->all( @promises )->then(
sub {
for my $tx (map { $_->[0] } @_) {
print "Service result: $tx->res->text";
}#end for
}#end sub
)->catch(
sub {
for my $err (map { $_->[0] } @_) {
print "ERROR: $err";
}#end for
}#end sub
)->wait;