All pastes #1913939 Raw Edit

Mojo async request

public text v1 · immutable
#1913939 ·published 2010-08-09 17:41 UTC
rendered paste body
package TestTest;

use strict;
use warnings;

use base 'Mojo::Base';

use Mojo::Client;
use Mojo::IOLoop;

sub request {
    my ($self) = @_;

    my $client = Mojo::Client->singleton;
    $client->ioloop(Mojo::IOLoop->singleton);
    my $stop_server = ! Mojo::IOLoop->singleton->is_running;
    $client->async->get(
        'http://google.com/',
        sub {
            my ($self, $tx) = @_;
            print "Got google!\n";
            $client->async->get(
                'http://localhost:8080',
                sub {
                    my ($self, $tx) = @_;
                    warn $tx->res->body;
                    Mojo::IOLoop->singleton->stop if $stop_server;
            })->process,
    })->process;
    Mojo::IOLoop->singleton->start;
    print "here\n";
}


1;