-
-
Save judofyr/60c8ed052f1150e99d1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Mojo/IOLoop/Resolver.pm b/lib/Mojo/IOLoop/Resolver.pm | |
index a0f1770..bbd2e4f 100644 | |
--- a/lib/Mojo/IOLoop/Resolver.pm | |
+++ b/lib/Mojo/IOLoop/Resolver.pm | |
@@ -76,6 +76,8 @@ my $DNS_TYPES = { | |
# "localhost" | |
our $LOCALHOST = '127.0.0.1'; | |
+my $ONGOING = {}; | |
+ | |
sub DESTROY { shift->_cleanup } | |
sub build { | |
@@ -123,6 +125,18 @@ sub lookup { | |
return $self->ioloop->defer(sub { $self->$cb($LOCALHOST) }) | |
if $name eq 'localhost'; | |
+ my $cbs = $ONGOING->{$name}; | |
+ if (defined $cbs) { | |
+ push $cbs, $cb; | |
+ return; | |
+ } | |
+ | |
+ $ONGOING->{$name} = [$cb]; | |
+ | |
+ my $done = sub { | |
+ $self->$_(@_) for @{delete $ONGOING->{$name}}; | |
+ }; | |
+ | |
# Resolve | |
$self->resolve( | |
$name => A => sub { | |
@@ -130,15 +144,15 @@ sub lookup { | |
# IPv4 | |
my $result = first { $_->[0] eq 'A' } @$records; | |
- return $self->$cb($result->[1]) if $result; | |
+ return $done->($result->[1]) if $result; | |
# IPv6 | |
$self->resolve( | |
$name => AAAA => sub { | |
my ($self, $records) = @_; | |
- return $self->$cb() | |
+ return $done->() | |
unless my $result = first { $_->[0] eq 'AAAA' } @$records; | |
- $self->$cb($result->[1]); | |
+ $done->($result->[1]); | |
} | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojo::UserAgent; | |
use v5.10; | |
my $u = Mojo::UserAgent->new; | |
sub yay { | |
say "START"; | |
$u->get('http://google.no/', sub { | |
say "DONE"; | |
}); | |
} | |
yay;yay;yay; | |
Mojo::IOLoop->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment