Hi Dan,
Thanks for the tip about the user agent object. But something's still not
right.
The following code works fine when run as a standalone Perl program.
use feature 'say';
use Mojo::IOLoop;
use Mojo::IOLoop::Delay;
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
my %dblist = (solarmon => 1,
solarmon_5min => 1,
solarmon_30min => 1,
solarmon_day => 1
);
my $url = 'http://wasd.vsm.com.au/echo/';
my $query = 'justanexample';
say "Initiating web requests ...";
Mojo::IOLoop->delay(
sub {
my $delay = shift;
foreach my $db (keys %dblist) {
say " Requesting $db ...";
$ua->get("$url$db&q=$query" => $delay->begin);
}
},
sub {
my $delay = shift;
say " Processing ", scalar @_, " results ...";
foreach my $tx (@_) {
say " Got ", $tx->result->body;
}
}
)->wait;
say "IOLoop->delay() test done";
and displays:
Initiating web requests ...
Requesting solarmon_day ...
Requesting solarmon ...
Requesting solarmon_30min ...
Requesting solarmon_5min ...
Processing 4 results ...
Got GET /echo/solarmon_day&q=justanexample HTTP/1.1
content-length: 0
accept-encoding: gzip
host: wasd.vsm.com.au
user-agent: Mojolicious (Perl)
Got GET /echo/solarmon&q=justanexample HTTP/1.1
user-agent: Mojolicious (Perl)
host: wasd.vsm.com.au
accept-encoding: gzip
content-length: 0
Got GET /echo/solarmon_30min&q=justanexample HTTP/1.1
user-agent: Mojolicious (Perl)
host: wasd.vsm.com.au
accept-encoding: gzip
content-length: 0
Got GET /echo/solarmon_5min&q=justanexample HTTP/1.1
accept-encoding: gzip
content-length: 0
user-agent: Mojolicious (Perl)
host: wasd.vsm.com.au
IOLoop->delay() test done
BUT if I embed that code into my Mojolicious web application (run using '
morbo') it behaves as if the *$delay->wait* did nothing:
Initiating web requests ...
IOLoop->delay() test done
Received 0 results
Requesting solarmon_day ...
Requesting solarmon_5min ...
Requesting solarmon_30min ...
Requesting solarmon ...
The requests are (apparently) being issued AFTER the *$delay->wait*
completes?
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.