On Wed, Dec 15, 1999 at 09:11:53AM -0800, [EMAIL PROTECTED] wrote:
> Not quite. It didn't work the first time, so I tried calling the at()
> method directly. Viz:
>
> $w = Event->timer(after => 1);
>
> $w->cb(sub {
> $now = Event::time();
> $next = $now + rand(20.);
> print "Now: ", scalar localtime($now), " Next: ", scalar localtime($next), "\n";
> $w->at($next);
> $w->again;
> });
> loop();
>
> The output looks like:
>
> [jsalmon@gw]$ ./ev.pl
> Now: Wed Dec 15 09:04:02 1999 Next: Wed Dec 15 09:04:12 1999
> Now: Wed Dec 15 09:04:04 1999 Next: Wed Dec 15 09:04:23 1999
> Now: Wed Dec 15 09:04:06 1999 Next: Wed Dec 15 09:04:12 1999
> Now: Wed Dec 15 09:04:08 1999 Next: Wed Dec 15 09:04:19 1999
Joshua Pritikin wrote:
Joshua> Hm hm hm... That's what I get for not testing. Try this:
Joshua> use Event qw(loop);
Joshua> $w = Event->timer(interval => 1);
Joshua> $w->cb(sub {
Joshua> $now = Event::time();
Joshua> $next = rand(20.);
Joshua> print "Now: ", scalar localtime($now), " Next: ", $next, "\n";
Joshua> $w->interval($next);
Joshua> });
Joshua> loop();
Bingo! That one works. Thanks. So the bottom line is: you must use
the interval attribute and the interval method if the timer is going
to be reused. Maybe this observation is worth a line in the pod?
Cheers,
John Salmon