For Programmers: Free Programming Magazines  


Home > Archive > PERL POE > January 2008 > events not getting handled









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author events not getting handled
Dave Schwartz

2008-01-25, 5:26 am

Hello,

I have a package method that runs in an infinite loop. And once in a
while based upon some logic,
it tries to fire an event. Somehow POE doesn't seem to be getting the event.
Is there something I am doing wrong here?

When I try to fire the event out of the while loop, I can see the
event handler being called without any issues.
I am a relatively new user for POE so apologies if my question sounds lame.
Gracias,
Dece

sub serve {
while(1) {
// do some processing here. we take about a few seconds to complete.
// once done, lets use poe to fire the event and notify
$kernel->yield("serviceComplete");
}
}
Martijn van Beers

2008-01-25, 9:25 am


On Fri, 2008-01-25 at 00:08 -0500, Dave Schwartz wrote:
> Hello,
>
> I have a package method that runs in an infinite loop. And once in a
> while based upon some logic,
> it tries to fire an event. Somehow POE doesn't seem to be getting the event.
> Is there something I am doing wrong here?
>
> When I try to fire the event out of the while loop, I can see the
> event handler being called without any issues.
> I am a relatively new user for POE so apologies if my question sounds lame.
> Gracias,
> Dece
>
> sub serve {
> while(1) {
> // do some processing here. we take about a few seconds to complete.
> // once done, lets use poe to fire the event and notify
> $kernel->yield("serviceComplete");
> }
> }


POE is cooperative, so if you never give up control like this, the
events will never be handled. What you want is something like this:

sub serve { # a POE event handler
my ($kernel) = @_[KERNEL, ...];

if (# check) {
$kernel->yield("serviceComplete");
}
$kernel->yield("serve_iteration") # loop
}


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com