Code Comments
Programming Forum and web based access to our favorite programming groups.Hi folks,
I've got a question about Tk::Repeat, I'm fairly familiar with Perl,
but it still gets a little confusing at times. Any answers or
references to info would be greatly appreciated. Here it goes:
$repeatid = $mw->Repeat(10, sub {...});
Inside the sub, a conditional tests for a pending queue, if it finds
one, it takes the info and passes it on to another sub to be
processed.
The code works fine, I'm just trying to figure out *how* it works.
Now the Repeat command executes the sub immediately, then once again
every 10ms, correct?
Everytime it runs, it's run as an event handler, which I assume means
it's not technically a loop, and any code after this command will
execute, interrupted every 10ms by the repeat 'event'.
I don't know if I'm on the right track or not, but I could use some
guidance.
Thanks everyone.
-jH
Post Follow-up to this message
"jacksonh" <parlei@AOL.COM> wrote in message
news:9123e7e0.0408280912.4d2e5b61@posting.google.com...
> Hi folks,
>
> I've got a question about Tk::Repeat, I'm fairly familiar with Perl,
> but it still gets a little confusing at times. Any answers or
> references to info would be greatly appreciated. Here it goes:
>
> $repeatid = $mw->Repeat(10, sub {...});
>
> Inside the sub, a conditional tests for a pending queue, if it finds
> one, it takes the info and passes it on to another sub to be
> processed.
>
> The code works fine, I'm just trying to figure out *how* it works.
>
> Now the Repeat command executes the sub immediately, then once again
> every 10ms, correct?
No. The repeat command also waits the specified time delay to start the
first instance of the subroutine. Of course with a 10 ms delay - you would
think it starts immediately. Try making it 10000 ms and you will see that
indeed it waits 10 seconds to start the first callback.
>
> Everytime it runs, it's run as an event handler, which I assume means
> it's not technically a loop, and any code after this command will
> execute, interrupted every 10ms by the repeat 'event'.
>
> I don't know if I'm on the right track or not, but I could use some
> guidance.
I had a similar question three years ago.
[url]http://groups.google.ca/groups?selm=a4_C6.457%24D4.40786%40www.newsranger.com[/url
]
Bottom line: The repeat will start it's 10 ms countdown to the next sub
*after* the completion of the first sub. This explanation also might not be
completely true as I'm sure that it also matters when the MainLoop gets
entered in order to handle all the pending events.
With no sample code supplied it is hard to determine what happens in your
case. i.e. If you fork and use a fileevent then your subroutine will end and
a new one will begin ~10ms later - meanwhile the other "process" is still
running. If you are doing this then you could have one process reporting
back later even if it started earlier. Anyways - there are lots of
variations on the theme - so sample code would help.
Jack
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.