Last active
December 28, 2015 07:29
-
-
Save olegwtf/7464791 to your computer and use it in GitHub Desktop.
Mojolicious & IO::Async
This file contains hidden or 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 strict; | |
use v5.10; | |
BEGIN { | |
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll'; | |
$ENV{MOJO_IOLOOP_DEBUG} = 1; | |
} | |
use Mojo::IOLoop; | |
use Mojo::UserAgent; | |
use Net::Async::HTTP; | |
use URI; | |
use IO::Async::Loop::Mojo; | |
my $ua = Mojo::UserAgent->new(); | |
my $loop = IO::Async::Loop::Mojo->new(); | |
my $http = Net::Async::HTTP->new(); | |
$loop->add($http); | |
for my $url (qw/google.ru mail.ru yandex.ru rambler.ru 2gis.ru/) { | |
$http->do_request(uri => URI->new( "http://$url/" ), on_response => sub { | |
say "Async: ", $url; | |
}); | |
$ua->get("http://$url", sub { | |
say "Mojo: ", $url; | |
}); | |
} | |
Mojo::IOLoop->start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment