Skip to content

Instantly share code, notes, and snippets.

@olegwtf
Last active December 28, 2015 07:29
Show Gist options
  • Save olegwtf/7464791 to your computer and use it in GitHub Desktop.
Save olegwtf/7464791 to your computer and use it in GitHub Desktop.
Mojolicious & IO::Async
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