bash has asked for the wisdom of the Perl Monks concerning the following question:
Im stuck on understanding how EV calculcate timers.
I have this code:
Iteration 3 - But I do not understand this case. Everything is the same. Why there is no timeout ???
Iteration 4 - And once again. So every even call to do() generate timeout, and every odd call doesn't generate.
Could you please clarify me about this behaviour?
output:#!/usr/bin/perl use common::sense; use AnyEvent::HTTP; use Data::Dumper; sub do { my $iter = shift; # It will resolve every timeout problems, but it is not question # AnyEvent->now_update; my $cv = AnyEvent->condvar; $cv->begin; http_get 'https://imasheep.hurrdurr.org/category/about.html', timeout => 2, sub { my ($body, $hdr) = @_; say "$iter $hdr->{Status}"; unless ($hdr->{Status} == 200) { warn Data::Dumper->Dump([$hdr],['hdr']); } $cv->end; } ; my $timer = AnyEvent->timer( after => 300, cb => sub { warn "Exit by timer"; $cv->send }, ); my ($n, $t) = (AnyEvent->now, AnyEvent->time); my $d = $t-$n; say "$iter diff = $d, time = $t, now = $n"; $cv->recv; } for (1..4) { &do($_); sleep(5); }
Iteration 2 - This is OK for me. Timer was set when internal time has 5 sec lag1 diff = 0.0233771800994873, time = 1427912097.54858, now = 1427912097 +.5252 1 200 2 diff = 5.0014123916626, time = 1427912103.05933, now = 1427912098.05 +791 2 596 $hdr = { 'Reason' => 'Connection timed out', 'URL' => 'https://imasheep.hurrdurr.org/category/about.html', 'Status' => 596 }; 3 diff = 5.00508308410645, time = 1427912108.06631, now = 1427912103.0 +6123 3 200 4 diff = 5.00244045257568, time = 1427912113.56622, now = 1427912108.5 +6378 4 596 $hdr = { 'Status' => 596, 'Reason' => 'Connection timed out', 'URL' => 'https://imasheep.hurrdurr.org/category/about.html' };
Iteration 3 - But I do not understand this case. Everything is the same. Why there is no timeout ???
Iteration 4 - And once again. So every even call to do() generate timeout, and every odd call doesn't generate.
Could you please clarify me about this behaviour?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: AnyEvent timers by EV
by Krambambuli (Curate) on Apr 03, 2015 at 18:40 UTC | |
by bash (Scribe) on Apr 04, 2015 at 13:31 UTC | |
by Krambambuli (Curate) on Apr 04, 2015 at 14:26 UTC | |
by Anonymous Monk on Apr 05, 2015 at 11:30 UTC | |
by bash (Scribe) on Apr 05, 2015 at 12:36 UTC | |
Re: AnyEvent timers for EV
by Anonymous Monk on Apr 01, 2015 at 18:35 UTC | |
Re: AnyEvent timers by EV
by Krambambuli (Curate) on Apr 03, 2015 at 16:10 UTC | |
Re: AnyEvent timers by EV
by Krambambuli (Curate) on Apr 03, 2015 at 16:31 UTC | |
by bash (Scribe) on Apr 04, 2015 at 13:23 UTC | |
Re: AnyEvent timers by EV
by sundialsvc4 (Abbot) on Apr 01, 2015 at 21:59 UTC | |
by Anonymous Monk on Apr 01, 2015 at 22:22 UTC | |
by sundialsvc4 (Abbot) on Apr 02, 2015 at 01:03 UTC | |
by bash (Scribe) on Apr 02, 2015 at 14:44 UTC | |
by Anonymous Monk on Apr 02, 2015 at 01:44 UTC |
Back to
Seekers of Perl Wisdom