2009/11/30 Jay Savage <daggerqu...@gmail.com>: > On Mon, Nov 30, 2009 at 10:45 AM, David Schmidt <zivildie...@gmail.com> wrote: >> Hello >> >> I would like to execute some Code after a certain amount of time has >> passed (then restart the timer but with a different time value) >> I looked at IO::Async::Timer::Countdown but this timer only gets >> started when used with a IO::Async::Loop. >> >> Basically I am looking for something as simple as >> >> my $do_it = { ... }; >> use MyTimer; >> my timer = MyTimer->new($delay, $do_it); >> >> and inside of $do_it I intend to start another timer. >> >> is there any simple class that does what I want? I failed to find it. >> >> thanks in advance >> >> david >> > > Hi David, > > I'm not really clear on what you're trying to do, here: looking at > IO::Async seems to indicate that you want your program to continue > while waiting for the timer, but your sample code would seem to pause > while the timer elapses. If you *don't* want to block for the timer, > the normal idom would be: > > eval { > local $SIG{ALRM} = { # usually dies }; > alarm $timeout; > # do something here until timeout > }; > if ($@) { #check $@ to make sure alarm died, not something else } > > > Either way, you should be able to use the built-in functions to > accomplish your task. See the docs for sleep(), alarm(), and select() > for more info. >
Hi Jay Sorry for the bad explanation of my problem. Yes my program has to continue while waiting for the timeout. You code example doesn't work for me because my program is an entire Catalyst application which I dont think is a good idea to put into an eval block. I would need the timer to run in the background and once it expires it should execute the code. david -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/