I'm trying to solve a problem that I think should be able to use
Event. I hope someone can point me in the right direction.
The basic structure is that I have a several tasks to perform repeatedly,
but I don't know when I want to do any given task again until I'm doing it.
Something like:
sub callback{
<do something>;
<figure out when we need to do it again>;
<arrange to do it again at the appointed time>;
}
I was hoping to do something like reset the 'after' attribute of the
event while I was in it, and then call again. The following code is
clearly not right, because there is no 'after' method in Event::timer,
but I hope it conveys what I'm trying to do:
#!/usr/local/bin/perl
use Event qw( loop );
$w = Event->timer(after => 1);
$w->cb(sub {
print scalar localtime, "\n";
$w->after(rand(10.));
$w->again;
});
loop();
Can anyone suggest a better approach for this kind of problem?
Thanks,
John Salmon