<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Hi,<br>
<br>
Le 28.11.2013 16:30, Fulko Hew a écrit :<br>
</div>
<blockquote
cite="mid:CAGuV3hNkoODXxLGg9=7j_SQY7dnW+up1H0=a-K_2Hyw3_e5njw@mail.gmail.com"
type="cite"><font face="courier new,monospace">I have a scenario
where I need to find out how much time<br>
is remaining on a timer (so that I can perform some calculation<br>
and then re-schedule something, based on that calculation).<br>
<br>
How can I find out something about the timer?<br>
Either when it was started, how much time has elapsed,<br>
or how much time is remaining?<br>
</font></blockquote>
<br>
The AnyEvent->timer returned object is created by the underlying
event loop.<br>
<br>
You have to look at its documentation to find how to introspect
these timer objects and so find whether it is possible or not... But
keep in mind that in this case, your AnyEvent code won't accept
another underlying event loop anymore.<br>
<br>
Else, you can use a closure for your short timer, that use a
variable containing the start date of your long timer. It is not
very accurate but in most cases it will suffice.<br>
<br>
my $starttime = time;<br>
my $long = AnyEvent->timer(<br>
after => 5,<br>
cb => sub { print "long timer done\n"; exit;
}<br>
);<br>
my $short = AnyEvent->timer(<br>
after => 2,<br>
cb => sub {<br>
print "time info part way through is: ",<br>
time - $starttime, "\n";<br>
}<br>
);<br>
...<br>
<br>
Regards,<br>
<br>
Max.<br>
<br>
<blockquote
cite="mid:CAGuV3hNkoODXxLGg9=7j_SQY7dnW+up1H0=a-K_2Hyw3_e5njw@mail.gmail.com"
type="cite"><font face="courier new,monospace"><br>
I tried the following test (based on what I read about EV)<br>
without success.<br>
<br>
use AnyEvent;<br>
<br>
# make a long timer, and a short timer that can 'look into'<br>
# the long timer to see what it can see<br>
<br>
my $long = AnyEvent->timer(<br>
after => 5,<br>
cb => sub { print "long timer done\n";
exit; }<br>
);<br>
my $short = AnyEvent->timer(<br>
after => 2,<br>
cb => sub {<br>
print "time info part way through
is: ",<br>
$long->at, "\n";<br>
}<br>
);<br>
<br>
my $cv = AnyEvent->condvar;<br>
$cv->wait;<br>
</font><br>
</blockquote>
<br>
</body>
</html>